$comment

在本页面

Definition

  • $comment
    • $comment查询运算符将 Comments 与带有查询谓词的任何表达式相关联。

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

$comment运算符的格式为:

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

Behavior

您可以将$comment与带有查询谓词的任何表达式一起使用,例如db.collection.update()aggregation pipeline$match阶段中的查询谓词。有关示例,请参见在聚合表达式上附加 Comments

Examples

附加 Comment 以查找

以下示例将$comment添加到find()操作:

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

在聚合表达式上附加 Comments

您可以将$comment与带有查询谓词的任何表达式一起使用。

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

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

See also