Set arbitrary query flags using a bitmask. To set the tailable flag: cursor.add_option(2)
(self, mask: int)
| 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. |