定义
cursor.maxAwaitTimeMS(<time limit>)重要
mongosh 方法
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
指定服务器等待与固定大小集合上的可追加游标查询匹配的新文档的最长时间。 有关迭代查询返回的游标的更多信息,请参阅:在
mongosh中迭代游标。The
maxAwaitTimeMS()method has the following prototype form:db.collection.find( { <query> }, { <projection> } ).tailable( { awaitData: true } ).maxAwaitTimeMS( <milliseconds> ) The
maxAwaitTimeMS()method has the following parameter:Parameter类型说明milliseconds整型
指定新文档的最长等待时间。
重要
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.
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
例子
查询固定大小的sales集合,查找代理机构 Mary Kay 的每周销售总额:
db.sales.find( { 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.