MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / add_option

Method add_option

pymongo/synchronous/cursor.py:362–380  ·  view source on GitHub ↗

Set arbitrary query flags using a bitmask. To set the tailable flag: cursor.add_option(2)

(self, mask: int)

Source from the content-addressed store, hash-verified

360 raise InvalidOperation("cannot set options after executing query")
361
362 def add_option(self, mask: int) -> Cursor[_DocumentType]:
363 """Set arbitrary query flags using a bitmask.
364
365 To set the tailable flag:
366 cursor.add_option(2)
367 """
368 if not isinstance(mask, int):
369 raise TypeError(f"mask must be an int, not {type(mask)}")
370 self._check_okay_to_chain()
371
372 if mask & _QUERY_OPTIONS["exhaust"]:
373 if self._limit:
374 raise InvalidOperation("Can't use limit and exhaust together.")
375 if self._collection.database.client.is_mongos:
376 raise InvalidOperation("Exhaust cursors are not supported by mongos")
377 self._exhaust = True
378
379 self._query_flags |= mask
380 return self
381
382 def remove_option(self, mask: int) -> Cursor[_DocumentType]:
383 """Unset arbitrary query flags using a bitmask.

Callers 9

test_exhaustMethod · 0.45
test_cloneMethod · 0.45
test_exhaustMethod · 0.45
test_cloneMethod · 0.45
parse_argsFunction · 0.45

Calls 2

_check_okay_to_chainMethod · 0.95
InvalidOperationClass · 0.90

Tested by 9

test_exhaustMethod · 0.36
test_cloneMethod · 0.36
test_exhaustMethod · 0.36
test_cloneMethod · 0.36
parse_argsFunction · 0.36