> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# cursor.comment() (mongosh method)

## Definition

**Important: mongosh Method**

This page documents a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.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 [MongoDB driver documentation.](https://www.mongodb.com/docs/drivers/)

Adds a `comment` field to the query.

[`cursor.comment()`](https://www.mongodb.com/docs/manual/reference/method/cursor.comment.md#mongodb-method-cursor.comment) has the following syntax:

```javascript
cursor.comment( <string> )
```

[`comment()`](https://www.mongodb.com/docs/manual/reference/method/cursor.comment.md#mongodb-method-cursor.comment) has the following parameter:

| Parameter | Type | Description |
| --- | --- | --- |
| `comment` | string | The comment to apply to the query. |

## Compatibility

This method is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/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, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Behavior

[`comment()`](https://www.mongodb.com/docs/manual/reference/method/cursor.comment.md#mongodb-method-cursor.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`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile)

- The [`QUERY`](https://www.mongodb.com/docs/manual/reference/log-messages.md#mongodb-data-QUERY) [log](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref) component

- [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp)

See [configure log verbosity](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-configure-verbosity) for the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) log, the [Database Profiler tutorial](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler), or the [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp) command.

## Example

The following operation attaches a comment to a query on the `restaurants` collection:

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

## Output Examples

### [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile)

The following is an excerpt from the [`system.profile`:](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile)

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

### [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) [log](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref)

The following is an excerpt from the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) log. It has been formatted for readability.

**Important:**

The verbosity level for [`QUERY`](https://www.mongodb.com/docs/manual/reference/log-messages.md#mongodb-data-QUERY) must be greater than `0`. See [Configure Log Verbosity Levels](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-configure-verbosity)

```javascript
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"
   }
   ...
```

### [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp)

Suppose the following operation is currently running on a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance:

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

Running the [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp) command returns the following:

```javascript
{
   "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
}
```
