Navigation
This version of the documentation is archived and no longer supported.

cursor.addOption()

cursor.addOption(<flag>)

Use the cursor.addOption() method on a cursor to add OP_QUERY wire protocol flags, such as the tailable flag, to change the behavior of queries.

Parameters:

The following example in the mongo shell adds the DBQuery.Option.tailable flag and the DBQuery.Option.awaitData flag to ensure that the query returns a tailable cursor:

var t = db.myCappedCollection;
var cursor = t.find().addOption(DBQuery.Option.tailable).
                      addOption(DBQuery.Option.awaitData)

This sequence of operations 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.