On this page
This is a
mongoshmethod. This is not the documentation for
Node.jsor other programming language specific driver methods.
In most cases,
mongoshmethods work the same way as the legacy
mongoshell methods. However, some legacy methods are unavailable in
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
Deprecated since v3.2
Starting in v3.2, the
cursor.addOption()operator is deprecated in
mongo. Use available cursor methods instead.
Used to change query behavior by setting the flags listed below.
cursor.addOption()method has the following parameter:ParameterTypeDescription
mongosh, you can use the cursor flags listed below. For the driver-specific list, see your driver documentation.
mongosh provides several additional cursor flags to
modify the behavior of the cursor.
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 secondary.
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:
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.