OPTIONS

cursor.comment()

Definition

cursor.comment()

New in version 3.2.

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.

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:

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:

db.restaurants.find(
   { "borough" : "Manhattan" }
).comment( "Find all Manhattan restaurants" )

Output Examples

system.profile

The following is an excerpt from the system.profile:

{
   "op" : "query",
   "ns" : "guidebook.restaurant",
   "query" : {
      "find" : "restaurant",
      "filter" : {
         "borough" : "Manhattan"
      },
      "comment" : "Find all Manhattan restaurants"
   },
   ...
}

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

2015-11-23T13:09:16.202-0500 I COMMAND  [conn1]
   command guidebook.restaurant command: find {
      find: "restaurant",
      filter: { "borough" : "Manhattan" },
      comment: "Find all Manhattan restaurants"
   }
   ...

db.currentOp()

Suppose the following operation is currently running on a mongod instance:

db.restaurant.find(
   { "borough" : "Manhattan" }
).comment("Find all Manhattan restaurants")

Running the db.currentOp() command returns the following:

{
   "inprog" : [
      {
         "desc" : "conn5",
         "threadId" : "0x10772e000",
         "connectionId" : 5,
         "client" : "127.0.0.1:62560",
         "active" : true,
         "opid" : 2249279,
         "secs_running" : 0,
         "microsecs_running" : NumberLong(258562),
         "op" : "query",
         "ns" : "guidebook.restaurant",
         "query" : {
            "find" : "restaurant",
            "filter" : { "borough" : "Manhattan" },
            "comment" : "Find all Manhattan restaurants"
         },
         ...
      },
      ...
   ],
   "ok" : 1
}

Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.