Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual


On this page

  • Definition
  • Example
cursor.maxAwaitTimeMS(<time limit>)


mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

Specifies the maximum time for the server to wait for new documents that match a tailable cursor query on a capped collection. For more information on iterating a cursor returned by a query, see: Iterate a Cursor in mongosh.

The maxAwaitTimeMS() method has the following prototype form:

{ <query> },
{ <projection> }
).tailable( { awaitData: true } ).maxAwaitTimeMS( <milliseconds> )

The maxAwaitTimeMS() method has the following parameter:

Specifies a maximum wait time for new documents.


This method, maxAwaitTimeMS(), sets a limit on how long a tailable cursor waits for the next response. maxTimeMS() sets a limit on total processing time.

Query the capped sales collection to find agent Mary Kay's weekly sales totals:

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

The highlighted line creates a tailable cursor on the sales collection. The maxAwaitTimeMS() sets a one second maximum wait time for the next cursor update.

←  cursor.max()cursor.maxTimeMS() →

On this page