Create a new cursor. Should not be called directly by application developers - see :meth:`~pymongo.collection.Collection.find` instead. .. seealso:: The MongoDB documentation on `cursors `_.
(
self,
collection: Collection[_DocumentType],
filter: Optional[Mapping[str, Any]] = None,
projection: Optional[Union[Mapping[str, Any], Iterable[str]]] = None,
skip: int = 0,
limit: int = 0,
no_cursor_timeout: bool = False,
cursor_type: int = CursorType.NON_TAILABLE,
sort: Optional[_Sort] = None,
allow_partial_results: bool = False,
oplog_replay: bool = False,
batch_size: int = 0,
collation: Optional[_CollationIn] = None,
hint: Optional[_Hint] = None,
max_scan: Optional[int] = None,
max_time_ms: Optional[int] = None,
max: Optional[_Sort] = None,
min: Optional[_Sort] = None,
return_key: Optional[bool] = None,
show_record_id: Optional[bool] = None,
snapshot: Optional[bool] = None,
comment: Optional[Any] = None,
session: Optional[ClientSession] = None,
allow_disk_use: Optional[bool] = None,
let: Optional[bool] = None,
)
| 73 | _getmore_class = _GetMore |
| 74 | |
| 75 | def __init__( |
| 76 | self, |
| 77 | collection: Collection[_DocumentType], |
| 78 | filter: Optional[Mapping[str, Any]] = None, |
| 79 | projection: Optional[Union[Mapping[str, Any], Iterable[str]]] = None, |
| 80 | skip: int = 0, |
| 81 | limit: int = 0, |
| 82 | no_cursor_timeout: bool = False, |
| 83 | cursor_type: int = CursorType.NON_TAILABLE, |
| 84 | sort: Optional[_Sort] = None, |
| 85 | allow_partial_results: bool = False, |
| 86 | oplog_replay: bool = False, |
| 87 | batch_size: int = 0, |
| 88 | collation: Optional[_CollationIn] = None, |
| 89 | hint: Optional[_Hint] = None, |
| 90 | max_scan: Optional[int] = None, |
| 91 | max_time_ms: Optional[int] = None, |
| 92 | max: Optional[_Sort] = None, |
| 93 | min: Optional[_Sort] = None, |
| 94 | return_key: Optional[bool] = None, |
| 95 | show_record_id: Optional[bool] = None, |
| 96 | snapshot: Optional[bool] = None, |
| 97 | comment: Optional[Any] = None, |
| 98 | session: Optional[ClientSession] = None, |
| 99 | allow_disk_use: Optional[bool] = None, |
| 100 | let: Optional[bool] = None, |
| 101 | ) -> None: |
| 102 | """Create a new cursor. |
| 103 | |
| 104 | Should not be called directly by application developers - see |
| 105 | :meth:`~pymongo.collection.Collection.find` instead. |
| 106 | |
| 107 | .. seealso:: The MongoDB documentation on `cursors <https://dochub.mongodb.org/core/cursors>`_. |
| 108 | """ |
| 109 | # Initialize all attributes used in __del__ before possibly raising |
| 110 | # an error to avoid attribute errors during garbage collection. |
| 111 | self._collection: Collection[_DocumentType] = collection |
| 112 | self._id: Any = None |
| 113 | self._exhaust = False |
| 114 | self._sock_mgr: Any = None |
| 115 | self._killed = False |
| 116 | self._session: Optional[ClientSession] |
| 117 | |
| 118 | if session: |
| 119 | self._session = session |
| 120 | self._session._attached_to_cursor = True |
| 121 | else: |
| 122 | self._session = None |
| 123 | |
| 124 | spec: Mapping[str, Any] = filter or {} |
| 125 | validate_is_mapping("filter", spec) |
| 126 | if not isinstance(skip, int): |
| 127 | raise TypeError(f"skip must be an instance of int, not {type(skip)}") |
| 128 | if not isinstance(limit, int): |
| 129 | raise TypeError(f"limit must be an instance of int, not {type(limit)}") |
| 130 | validate_boolean("no_cursor_timeout", no_cursor_timeout) |
| 131 | if no_cursor_timeout and self._session and self._session._implicit: |
| 132 | warnings.warn( |
no test coverage detected