On this page本页内容
cursor.
addOption
(flag)¶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驱动程序文档。
Deprecated since v3.2
Starting in v3.2, the cursor.addOption()
operator is deprecated in the mongo
shell. In the mongo
shell, use available cursor methods instead.
Adds OP_QUERY
wire protocol flags, such as the tailable
flag, to change the behavior of queries.
The cursor.addOption()
method has the following parameter:
flag |
flag | OP_QUERY wire protocol flag. For the mongo shell, you can use the cursor flags listed below. For the driver-specific list, see your driver documentation. |
The mongo
shell provides several additional cursor flags to modify the behavior of the cursor.
Flag | |
---|---|
|
Sets the cursor not to close once the last data is received, allowing the query to continue returning data added after the initial results were exhausted. |
|
Allows querying of a replica slave. |
|
Prevents the server from timing out idle cursors. |
|
For use with .. data:: DBQuery.Option.tailable; sets the cursor to block and await data for a while rather than returning no data. The cursor will return no data once the timeout has expired. |
|
Sets the cursor to return all data returned by the query at once rather than splitting the results into batches. |
|
Sets the cursor to return partial data from a query against a sharded cluster in which some shards do not respond rather than throwing an error. |
The following example adds the DBQuery.Option.tailable
flag and the DBQuery.Option.awaitData
flag to ensure that the query returns a tailable cursor. 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:
Warning
Adding incorrect wire protocol flags can cause problems and/or extra server load.