Definition定义
cursor.tailable()-
Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. 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驱动程序文档。Marks the cursor as tailable keeping it open even when the client exhausts all results.将游标标记为可尾随,即使客户端用尽所有结果,游标也会保持打开状态。For use against a capped collection only. Using仅用于封顶集合。对非上限集合使用tailable()against a non-capped collection returns an error.tailable()会返回错误。cursor.tailable()uses the following syntax:使用以下语法:cursor.tailable( { awaitData : <boolean> } )~cursor.tailable()has the following parameter:具有以下参数:Parameter参数Type类型Description描述awaitDataboolean布尔值Optional.可选。For use with与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.DBQuery.Option.tailable一起使用。将游标设置为在没有数据可用时阻止查询线程,并在设定的时间内等待数据,而不是立即返回无数据。The cursor returns no data only if the timeout expires.只有当超时到期时,游标才会返回任何数据。By default, if默认情况下,如果在创建游标的命令上设置了maxTimeMSis set on the command that created the cursor, then the timeout forawaitDatais the remaining time. Otherwise, the default timeout is 1000 milliseconds.maxTimeMS,则awaitData的超时时间是剩余时间。否则,默认超时为1000毫秒。You can set a timeout when running在启用了getMoreon a cursor withawaitDataenabled.awaitData的游标上运行getMore时,可以设置超时。Defaults to默认为false.false。Returns:返回The cursor that~cursor.tailable()is attached to.~cursor.tailable()所连接的游标。
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的源代码可用、免费使用和自我管理版本
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 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. awaitData为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.请参阅可尾随游标。