cursor.maxTimeMS()

Definition

New in version 2.6.

  • cursor.maxTimeMS()

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

Specifies a cumulative time limit in milliseconds for processingoperations on a cursor.

The maxTimeMS() method has the followingparameter:

ParameterTypeDescriptionmillisecondsintegerSpecifies a cumulative time limit in milliseconds for processing operationson the cursor.

Important

maxTimeMS() is not related to theNoCursorTimeout query flag. maxTimeMS()relates to processing time, while NoCursorTimeout relatesto idle time. A cursor’s idle time does not contribute towards itsprocessing time.

Behaviors

MongoDB targets operations for termination if the associated cursorexceeds its allotted time limit. MongoDB terminates operations thatexceed their allotted time limit using the same mechanism asdb.killOp(). MongoDB only terminates an operation at one ofits designated interrupt points.

MongoDB does not count network latency between the client and theserver towards a cursor’s time limit. For a sharded cluster, however,MongoDB does include the latency between the mongos andmongod instances towards this time limit.

Queries that generate multiple batches of results continue to returnbatches until the cursor exceeds its allotted time limit.

Examples

Example

The following query specifies a time limit of 50 milliseconds:

  1. db.collection.find({description: /August [0-9]+, 1969/}).maxTimeMS(50)