- Reference >
- Operators >
- Query and Projection Operators >
- $comment
$comment¶
On this page
Definition¶
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:
If the Database Profiler is enabled,
the following output shows the comment in the
system.profile
collection:
Comments also appear in the MongoDB log
if the database profiler level is set
to 2 and slowms is set to
0ms. This db.setProfilingLevel()
command sets these two
parameters:
The comment for the previous db.records.find()
example
then appears as follows in the
MongoDB log: