$comment

    在本页面

    $comment

    $comment查询操作符将注释与任何具有查询谓词的表达式关联起来。

    由于注释会传播到profile日志,因此添加注释可以使您的个人资料数据更易于解释和跟踪。

    $comment运算符的形式为:

    1. db.collection.find( { <query>, $comment: <comment> } )

    行为

    您可以将_ $comment与任何带查询谓词的表达式一起使用,例如聚合管道中db.collection.update()或聚合$match阶段中的查询谓词 。有关示例,请参见对聚合表达式附加注释。

    例子

    附加评论到find

    以下示例$commentfind()操作中添加了:

    1. db.records.find(
    2. {
    3. x: { $mod: [ 2, 0 ] },
    4. $comment: "Find even values."
    5. }
    6. )

    在聚合表达式上附加注释

    您可以对$comment带查询谓词的任何表达式使用。

    以下示例在$match阶段中使用运算符$comment来阐明操作:

    1. db.records.aggregate( [
    2. { $match: { x: { $gt: 0 }, $comment: "Don't allow negative inputs." } },
    3. { $group : { _id: { $mod: [ "$x", 2 ] }, total: { $sum: "$x" } } }
    4. ] )

    也可以看看

    $comment

    译者:李冠飞

    校对: