- Reference >
mongosh
Methods >- Cursor Methods >
- cursor.comment()
cursor.comment()¶
On this page
Definition¶
-
cursor.
comment
()¶ Important
mongosh
MethodThis page documents a
mongosh
method. This is not the documentation for a language-specific driver such as Node.js.For MongoDB API drivers, refer to the language-specific :driver:`MongoDB driver documentation </>`.
For the legacy
mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:Adds a
comment
field to the query.cursor.comment()
has the following syntax:comment()
has the following parameter:Parameter Type Description comment
string The comment to apply to the query.
Behavior¶
comment()
associates a comment string with the
find operation. This can make it easier to track a particular query in the
following diagnostic outputs:
- The
system.profile
- The
QUERY
log component db.currentOp()
See configure log verbosity for the
mongod
log, the
Database Profiler tutorial, or
the db.currentOp()
command.
Example¶
The following operation attaches a comment to a query on the restaurants
collection:
Output Examples¶
system.profile
¶
The following is an excerpt from the
system.profile
:
mongod
log¶
The following is an excerpt from the mongod
log. It has been
formatted for readability.
Important
The verbosity level for QUERY
must be greater than 0
.
See Configure Log Verbosity Levels
db.currentOp()
¶
Suppose the following operation is currently running on a mongod
instance:
Running the db.currentOp()
command returns the following: