cursor.addOption()
Definition
mongo
Shell Method
This page documents the mongo
shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.
Deprecated since v3.2
Starting in v3.2, the cursor.addOption()
operator is deprecated in themongo
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:
ParameterTypeDescriptionflag
flagOP_QUERY
wire protocol flag. For the mongo
shell,you can use the cursor flags listed below. For the driver-specificlist, see your driver documentation.
Flags
The mongo
shell provides several additional cursor flags tomodify the behavior of the cursor.
Example
The following example adds the DBQuery.Option.tailable
flag and theDBQuery.Option.awaitData
flag to ensure that the query returns atailable cursor. The sequence creates a cursor that will wait for fewseconds after returning the full result set so that it can capture andreturn additional data added during the query:
- 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/orextra server load.