On this page本页内容
cursor.addOption(flag)
This is a mongosh
method. This is not the documentation for Node.js
or other programming language specific driver methods.
In most cases, mongosh
methods work the same way as the legacy mongo
shell methods. However, some legacy methods are unavailable in mongosh
.
For the legacy mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
Starting in v3.2, the 从v3.2开始,mongo中不推荐使用cursor.addOption()
operator is deprecated in mongo
. cursor.addOption()
运算符。Use available cursor methods instead.请改用可用的游标方法。
Used to change query behavior by setting the flags listed below.用于通过设置下面列出的标志来更改查询行为。
The cursor.addOption()
method has the following parameter:cursor.addOption()
方法具有以下参数:
flag | flag | mongosh , you can use the cursor flags listed below. mongosh ,可以使用下面列出的游标标志。 |
mongosh
provides several additional cursor flags to modify the behavior of the cursor.提供了几个附加的游标标志来修改游标的行为。
Flag | |
---|---|
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 that will wait for few seconds after returning the full result set so that it can capture and return additional data added during the query:该序列创建一个游标,在返回完整结果集后将等待几秒钟,以便它可以捕获并返回查询期间添加的其他数据:
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.添加不正确的连线协议标志可能会导致问题和/或额外的服务器负载。