翻译或纠错本页面

cursor.maxTimeMS()

Definition

2.6 新版功能.

cursor.maxTimeMS(<time limit>)

Specifies a cumulative time limit in milliseconds for processing operations on a cursor.

The maxTimeMS() method has the following parameter:

Parameter Type Description
milliseconds integer Specifies a cumulative time limit in milliseconds for processing operations on the cursor.

重要

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

Behaviors

MongoDB targets operations for termination if the associated cursor exceeds its allotted time limit. MongoDB terminates operations that exceed their allotted time limit, using the same mechanism as db.killOp(). MongoDB only terminates an operation at one of its designated interrupt points.

MongoDB does not count network latency towards a cursor’s time limit.

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

Examples

Example

The following query specifies a time limit of 50 milliseconds:

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