cursor.addOption()
On this page本页内容
Definition定义
cursor.addOption(flag)
- 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.
NoteDeprecated 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描述flag
flag For对于mongosh
, you can use the cursor flags listed below.mongosh
,您可以使用下面列出的游标标志。For the driver-specific list, see your driver documentation.有关特定于驱动程序的列表,请参阅驱动程序文档。
Flags标记
mongosh
provides several additional cursor flags to modify the behavior of the cursor.提供了几个额外的游标标志来修改游标的行为。
Flag | |
---|---|
DBQuery.Option.tailable
| |
DBQuery.Option.slaveOk
| |
DBQuery.Option.noTimeout
| |
DBQuery.Option.awaitData
| DBQuery.Option.tailable . 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)
Adding incorrect wire protocol flags can cause problems and/or extra server load.添加不正确的有线协议标志可能会导致问题和/或额外的服务器负载。