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