Definition定义
cursor.addOption(flag)-
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驱动程序文档。Note
Deprecated since v3.2自v3.2以来已弃用Starting in v3.2, the从v3.2开始,mongo中不推荐使用cursor.addOption()operator is deprecated inmongo. Use available cursor methods instead.cursor.addOption()运算符。请改用可用的游标方法。Used to change query behavior by setting the flags listed below.用于通过设置下面列出的标志来更改查询行为。Thecursor.addOption()method has the following parameter:cursor.addOption()方法有以下参数:Parameter参数Type类型Description描述flagflag For对于mongosh, you can use the cursor flags listed below. For the driver-specific list, see your driver documentation.mongosh,您可以使用下面列出的游标标志。有关特定于驱动程序的列表,请参阅驱动程序文档。
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部署的完全托管服务
Important
This command has limited support in all MongoDB Atlas clusters. For more information, see Unsupported Commands.此命令在所有MongoDB 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的源代码可用、免费使用和自我管理版本
Flags标记
mongosh provides several additional cursor flags to modify the behavior of the cursor.提供了几个额外的游标标志来修改游标的行为。
DBQuery.Option.tailable | |
DBQuery.Option.slaveOk | |
DBQuery.Option.noTimeout | |
DBQuery.Option.awaitData | 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.DBQuery.Option.tailable一起使用。将游标设置为在没有数据可用时阻止查询线程,并在设定的时间内等待数据,而不是立即返回无数据。只有当超时到期时,游标才会返回任何数据。 |
DBQuery.Option.exhaust | |
DBQuery.Option.partial |
Example示例
The following example adds the 以下示例添加了DBQuery.Option.tailable flag and the DBQuery.Option.awaitData flag to ensure that the query returns a tailable cursor. DBQuery.Option.tailable标志和DBQuery.Option.awaitData标志,以确保查询返回可尾随游标。The sequence creates a cursor. After returning the full result set, it waits for the default interval of 1000 milliseconds so that it can capture and return additional data added during the query:该序列创建了一个游标。返回完整结果集后,它会等待默认的1000毫秒间隔,以便捕获并返回查询过程中添加的其他数据:
var t = db.myCappedCollection;
var cursor = t.find().addOption(DBQuery.Option.tailable).
addOption(DBQuery.Option.awaitData)
Warning
Adding incorrect wire protocol flags can cause problems and/or extra server load.添加不正确的有线协议标志可能会导致问题和/或额外的服务器负载。