Database Manual / Reference / mongosh Methods / Cursors

cursor.maxAwaitTimeMS() (mongosh method方法)

Definition定义

cursor.maxAwaitTimeMS(<time limit>)

Important

mongosh Method方法

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.本页记录了一种mongosh方法。这不是针对特定语言驱动程序(如Node.js)的文档。

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档

Specifies the maximum time for the server to wait for new documents that match a tailable cursor query on a capped collection. 指定服务器等待与封顶集合上的可尾随游标查询匹配的新文档的最长时间。For more information on iterating a cursor returned by a query, see: Iterate a Cursor in mongosh.有关迭代查询返回的游标的更多信息,请参阅:mongosh中迭代游标

The maxAwaitTimeMS() method has the following prototype form:maxAwaitTimeMS()方法具有以下原型形式:

db.collection.find(
{ <query> },
{ <projection> }
).tailable( { awaitData: true } ).maxAwaitTimeMS( <milliseconds> )

The maxAwaitTimeMS() method has the following parameter:maxAwaitTimeMS()方法有以下参数:

Parameter参数Type类型Description描述
millisecondsinteger整数Specifies a maximum wait time for new documents.指定新文档的最长等待时间。

Important

This method, maxAwaitTimeMS(), sets a limit on how long a tailable cursor waits for the next response. 此方法maxAwaitTimeMS()设置了可跟踪游标等待下一个响应的时间限制。maxTimeMS() sets a limit on total processing time.maxTimeMS()设置总处理时间的限制。

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Example示例

Query the capped sales collection to find agent Mary Kay's weekly sales totals:查询封顶集合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. 突出显示的行在sales集合上创建了一个可尾随游标。The maxAwaitTimeMS() sets a one second maximum wait time for the next cursor update.maxAwaitTimeMS()设置下一次游标更新的最大等待时间为1秒。