$maxTimeMS

$maxTimeMS

Note

2.6 版中的新增功能:$maxTimeMS运算符指定了以毫秒为单位的累积时间限制,用于在光标上进行处理操作。 MongoDB 最早在interrupt point之后中断操作。

mongo shell 提供cursor.maxTimeMS()方法

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

您还可以采用以下两种形式之一指定选项:

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

中断的操作将返回类似于以下内容的错误消息:

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