$maxTimeMS

$maxTimeMS

Deprecated since v3.2从v3开始就不推荐了。2.

Starting in v3.2, the $maxTimeMS operator is deprecated in the mongo shell. 从v3.2开始,$maxTimeMS运算符在mongo shell中不受欢迎。In the mongo shell, use cursor.maxTimeMS() instead.mongo shell中,请用cursor.maxTimeMS()

The $maxTimeMS operator specifies a cumulative time limit in milliseconds for processing operations on the cursor. $maxTimeMS运算符指定处理游标上的操作的累积时间限制(以毫秒为单位)。MongoDB interrupts the operation at the earliest following interrupt point.MongoDB在最早的中断点中断操作。

The mongo shell provides the cursor.maxTimeMS() methodmongo shell提供了cursor.maxTimeMS()方法

db.collection.find().maxTimeMS(100)

You can also specify the option in either of the following forms:您还可以通过以下任一形式指定该选项:

db.collection.find( { $query: { }, $maxTimeMS: 100 } )
db.collection.find( { } )._addSpecial("$maxTimeMS", 100)

Interrupted operations return an error message similar to the following:中断的操作会返回类似于以下内容的错误消息:

error: { "$err" : "operation exceeded time limit", "code" : 50 }