Docs HomeMongoDB Manual

cursor.maxAwaitTimeMS()

On this page本页内容

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.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

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