Navigation
This version of the documentation is archived and no longer supported.

$comment

Definition

$comment

The $comment query operator associates a comment to any expression taking a query predicate.

Because comments propagate to the profile log, adding a comment can make your profile data easier to interpret and trace.

The $comment operator has the form:

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

Behavior

You can use the $comment with any expression taking a query predicate, such as the query predicate in db.collection.update() or in the $match stage of the aggregation pipeline. For an example, see Attach a Comment to an Aggregation Expression.

Examples

Attach a Comment to find

The following example adds a $comment to a find() operation :

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

Attach a Comment to an Aggregation Expression

You can use the $comment with any expression taking a query predicate.

The following examples uses the $comment operator in the $match stage to clarify the operation:

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

See also

$comment