cursor.tailable()

On this page本页内容

Definition定义

cursor.tailable()

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

New in version 3.2.版本3.2中的新功能。

Marks the cursor as tailable.将游标标记为可裁剪。

For use against a capped collection only. 仅适用于封顶集合Using tailable against a non-capped collection will return an error.对无上限集合使用tailable将返回错误。

cursor.tailable() uses the following syntax:使用以下语法:

cursor.tailable( { awaitData : <boolean> } )

tailable() has the following parameter:具有以下参数:

Parameter参数Type类型Description描述
awaitData boolean

Optional.可选。When true, enables awaitData.如果为true,则启用awaitData

awaitData is false by default.默认情况下,awaitDatafalse

Returns:The cursor that tailable() is attached to.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 is set to true, when the cursor reaches the end of the capped collection, MongoDB blocks the query thread for a period of time waiting for new data to arrive. 如果awaitData设置为true,当游标到达封顶集合的末尾时,MongoDB将阻塞查询线程一段时间,等待新数据到达。When new data is inserted into the capped collection, the blocked thread is signaled to wake up and return the next batch to the client.当新数据被插入到封顶集合中时,阻塞的线程会收到唤醒信号,并将下一批数据返回给客户端。

See Tailable Cursors.请参见可裁剪游标