- Reference >
- JavaScript Methods >
- cursor.addOption()
cursor.addOption()¶
-
cursor.addOption(<flag>)¶ Use the
cursor.addOption()method on a cursor to addOP_QUERYwire protocol flags, such as thetailableflag, to change the behavior of queries.Parameters: - flag –
OP_QUERYwire protocol flag. See :meta-driver:`MongoDB wire protocol </legacy/mongodb-wire-protocol/?pageVersion=106#op-query>` for more information on MongoDB Wire Protocols and the OP_QUERY flags.For the
mongoshell, you can use the cursor flags listed in the Cursor Flags section. For the driver-specific list, see your driver documentation.
The following example in the
mongoshell adds theDBQuery.Option.tailableflag and theDBQuery.Option.awaitDataflag to ensure that the query returns a tailable cursor: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.
- flag –