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

Method _refresh

pymongo/asynchronous/cursor.py:1055–1117  ·  view source on GitHub ↗

Refreshes the cursor with more data from Mongo. Returns the length of self._data after refresh. Will exit early if self._data is already non-empty. Raises OperationFailure when the cursor cannot be refreshed due to an error on the query.

(self)

Source from the content-addressed store, hash-verified

1053 await self.close()
1054
1055 async def _refresh(self) -> int:
1056 """Refreshes the cursor with more data from Mongo.
1057
1058 Returns the length of self._data after refresh. Will exit early if
1059 self._data is already non-empty. Raises OperationFailure when the
1060 cursor cannot be refreshed due to an error on the query.
1061 """
1062 if len(self._data) or self._killed:
1063 return len(self._data)
1064
1065 if not self._session:
1066 self._session = self._collection.database.client._ensure_session()
1067
1068 if self._id is None: # Query
1069 if (self._min or self._max) and not self._hint:
1070 raise InvalidOperation(
1071 "Passing a 'hint' is required when using the min/max query"
1072 " option to ensure the query utilizes the correct index"
1073 )
1074 q = self._query_class(
1075 self._query_flags,
1076 self._collection.database.name,
1077 self._collection.name,
1078 self._skip,
1079 self._query_spec(),
1080 self._projection,
1081 self._codec_options,
1082 self._get_read_preference(),
1083 self._limit,
1084 self._batch_size,
1085 self._read_concern,
1086 self._collation,
1087 self._session,
1088 self._collection.database.client,
1089 self._allow_disk_use,
1090 self._exhaust,
1091 )
1092 await self._send_message(q)
1093 elif self._id: # Get More
1094 if self._limit:
1095 limit = self._limit - self._retrieved
1096 if self._batch_size:
1097 limit = min(limit, self._batch_size)
1098 else:
1099 limit = self._batch_size
1100 # Exhaust cursors don't send getMore messages.
1101 g = self._getmore_class(
1102 self._dbname,
1103 self._collname,
1104 limit,
1105 self._id,
1106 self._codec_options,
1107 self._get_read_preference(),
1108 self._session,
1109 self._collection.database.client,
1110 self._max_await_time_ms,
1111 self._sock_mgr,
1112 self._exhaust,

Callers 2

nextMethod · 0.95
_next_batchMethod · 0.95

Calls 5

_query_specMethod · 0.95
_get_read_preferenceMethod · 0.95
_send_messageMethod · 0.95
InvalidOperationClass · 0.90
_ensure_sessionMethod · 0.45

Tested by

no test coverage detected