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

Class Cursor

pymongo/synchronous/cursor.py:71–1172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69
70
71class Cursor(_CursorBase[_DocumentType]):
72 _query_class = _Query
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):

Callers 3

test_stale_getmoreMethod · 0.90
findMethod · 0.90
explainMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_stale_getmoreMethod · 0.72