cursor.tailable()
On this page本页内容
Definition定义
cursor.tailable()
- 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.
Marks the cursor as tailable keeping it open even when the client exhausts all results.将游标标记为可裁剪,即使客户端耗尽了所有结果,也保持其打开状态。For use against a capped collection only. Using仅适用于封顶集合。对非封顶集合使用~cursor.tailable()
against a non-capped collection returns an error.~cursor.tailable()
会返回一个错误。cursor.tailable()
uses the following syntax:使用以下语法:cursor.tailable( { awaitData : <boolean> } )
~cursor.tailable()
has the following parameter:具有以下参数:Parameter参数Type类型Description描述awaitData
boolean Optional.可选的。For use with用于DBQuery.Option.tailable
.DBQuery.Option.tailable
。Sets the cursor to block the query thread when no data is available and await data for a set time instead of immediately returning no data.将游标设置为在没有可用数据时阻塞查询线程,并等待数据一段时间,而不是立即返回任何数据。The cursor returns no data only if the timeout expires.只有在超时到期时,游标才不返回任何数据。
By default, if默认情况下,如果在创建游标的命令上设置了maxTimeMS
is set on the command that created the cursor, then the timeout forawaitData
is the remaining time.maxTimeMS
,那么awaitData
的超时就是剩余时间。Otherwise, the default timeout is 1000 milliseconds.否则,默认超时为1000
毫秒。
You can set a timeout when runninggetMore
on a cursor withawaitData
enabled.在awaitData
启用的情况下,可以在游标上运行getMore
时设置超时。
Defaults to默认为false
.false
。Returns:返回值:The cursor that~cursor.tailable()
is attached to.~cursor.tailable()
所附加的游标。
Behavior行为
A tailable cursor performs a collection scan over a capped collection. It remains open even after reaching the end of the collection. Applications can continue to iterate the tailable cursor as new data is inserted into the collection.一个可裁剪的游标在封顶集合上执行集合扫描。即使到达集合的末尾,它仍然是开放的。当新数据插入到集合中时,应用程序可以继续迭代可裁剪的游标。
If 如果awaitData为awaitData
is true
, when the cursor reaches the end of the capped collection, mongod
blocks the query thread for the timeout interval and waits for new data to arrive. true
,则当游标到达带帽集合的末尾时,mongod
会在超时间隔内阻塞查询线程,并等待新数据到达。When new data is inserted into the capped collection, 当新数据被插入到有上限的集合中时,mongod
signals the blocked thread to wake and return the next batch to the client.mongod
会向被阻止的线程发出信号以唤醒并将下一批返回给客户端。
See Tailable Cursors.请参见可尾随游标。