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

# cursor.maxAwaitTimeMS() (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/)

Specifies the maximum time for the server to wait for new documents that match a [tailable cursor](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) query on a [capped collection](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection). For more information on iterating a cursor returned by a query, see: [Iterate a Cursor in `mongosh`.](https://www.mongodb.com/docs/manual/tutorial/iterate-a-cursor.md#std-label-read-operations-cursors)

The [`maxAwaitTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxawaittimems.md#mongodb-method-cursor.maxAwaitTimeMS) method has the following prototype form:

```javascript
db.collection.find(
   { <query> },
   { <projection> }
).tailable( { awaitData: true } ).maxAwaitTimeMS( <milliseconds> )
```

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

| Parameter | Type | Description |
| --- | --- | --- |
| `milliseconds` | integer | Specifies a maximum wait time for new documents. |

**Important:**

This method, [`maxAwaitTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxawaittimems.md#mongodb-method-cursor.maxAwaitTimeMS), sets a limit on how long a [tailable cursor](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) waits for the next response. [`maxTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxtimems.md#mongodb-method-cursor.maxTimeMS) sets a limit on total processing time.

## 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

## Example

Query the [capped](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection) `sales` collection to find agent Mary Kay's weekly sales totals:

```javascript
db.sales.find(
   { agent: "Mary Kay" },
   { _id: 0, agent: 1, weeklyTotal: 1  }
).tailable( { awaitData: true } ).maxAwaitTimeMS( 1000 )
```

The highlighted line creates a [tailable cursor](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) on the `sales` collection. The [`maxAwaitTimeMS()`](https://www.mongodb.com/docs/manual/reference/method/cursor.maxawaittimems.md#mongodb-method-cursor.maxAwaitTimeMS) sets a one second maximum wait time for the next cursor update.
