cursor.maxAwaitTimeMS()

On this page本页内容

Definition定义

cursor.maxAwaitTimeMS(<time limit>)
Important重要
mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

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描述
millisecondsintegerSpecifies 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.设置总处理时间的限制。

Example示例

Query the capped sales collection to find agent Mary Kay's weekly sales totals:查询封顶sales额集合以查找经纪人玛丽·凯的每周销售额总计:

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.maxAwaitTimeMS()设置下一次游标更新的最长等待时间为1秒。

←  cursor.max()cursor.maxTimeMS() →