cursor.comment() (original) (raw)
cursor.comment()
Important
mongosh Method
This 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-specificMongoDB driver documentation.
Adds a comment
field to the query.
cursor.comment() has the following syntax:
cursor.comment( <string> )
comment() has the following parameter:
Parameter | Type | Description |
---|---|---|
comment | string | The comment to apply to the query. |
This method is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Note
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, seeUnsupported Commands.
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
- MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
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 themongod log, theDatabase Profiler tutorial, or the db.currentOp() command.
The following operation attaches a comment to a query on the restaurants
collection:
db.restaurants.find(
{ "borough" : "Manhattan" }
).comment( "Find all Manhattan restaurants" )
The following is an excerpt from thesystem.profile:
{
"op" : "query",
"ns" : "guidebook.restaurant",
"query" : {
"find" : "restaurant",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants"
},
...
}
The following is an excerpt from the mongod log. It has been formatted for readability.
Important
2015-11-23T13:09:16.202-05:00 I COMMAND [conn1]
command guidebook.restaurant command: find {
find: "restaurant",
filter: { "borough" : "Manhattan" },
comment: "Find all Manhattan restaurants"
}
...
Suppose the following operation is currently running on a mongodinstance:
db.restaurants.find(
{ "borough" : "Manhattan" }
).comment("Find all Manhattan restaurants")
Running the db.currentOp() command returns the following:
{
"inprog" : [
{
"host" : "198.51.100.1:27017",
"desc" : "conn3",
"connectionId" : 3,
...
"op" : "query",
"ns" : "test.$cmd",
"command" : {
"find" : "restaurants",
"filter" : {
"borough" : "Manhattan"
},
"comment" : "Find all Manhattan restaurants",
"$db" : "test"
},
"numYields" : 0,
...
}
],
"ok" : 1
}