- Reference >
- JavaScript Methods >
- cursor.addOption()
cursor.addOption()¶
-
cursor.
addOption
(<flag>)¶ Use the
cursor.addOption()
method on a cursor to addOP_QUERY
wire protocol flags, such as thetailable
flag, to change the behavior of queries.Parameters: - flag –
OP_QUERY
wire 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
mongo
shell, 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
mongo
shell adds theDBQuery.Option.tailable
flag and theDBQuery.Option.awaitData
flag 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 –