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

Method run_operation

pymongo/synchronous/server.py:138–348  ·  view source on GitHub ↗

Run a _Query or _GetMore operation and return a Response object. This method is used only to run _Query/_GetMore operations from cursors. Can raise ConnectionFailure, OperationFailure, etc. :param conn: A Connection instance. :param operation: A _Query or _G

(
        self,
        conn: Connection,
        operation: Union[_Query, _GetMore],
        read_preference: _ServerMode,
        listeners: Optional[_EventListeners],
        unpack_res: Callable[..., list[_DocumentOut]],
        client: MongoClient[Any],
    )

Source from the content-addressed store, hash-verified

136
137 @_handle_reauth
138 def run_operation(
139 self,
140 conn: Connection,
141 operation: Union[_Query, _GetMore],
142 read_preference: _ServerMode,
143 listeners: Optional[_EventListeners],
144 unpack_res: Callable[..., list[_DocumentOut]],
145 client: MongoClient[Any],
146 ) -> Response:
147 """Run a _Query or _GetMore operation and return a Response object.
148
149 This method is used only to run _Query/_GetMore operations from
150 cursors.
151 Can raise ConnectionFailure, OperationFailure, etc.
152
153 :param conn: A Connection instance.
154 :param operation: A _Query or _GetMore object.
155 :param read_preference: The read preference to use.
156 :param listeners: Instance of _EventListeners or None.
157 :param unpack_res: A callable that decodes the wire protocol response.
158 :param client: A MongoClient instance.
159 """
160 assert listeners is not None
161 publish = listeners.enabled_for_commands
162 start = datetime.now()
163
164 use_cmd = operation.use_command(conn)
165 more_to_come = operation.conn_mgr and operation.conn_mgr.more_to_come
166 cmd, dbn = self.operation_to_command(operation, conn, use_cmd)
167 if more_to_come:
168 request_id = 0
169 else:
170 message = operation.get_message(read_preference, conn, use_cmd)
171 request_id, data, max_doc_size = self._split_message(message)
172
173 if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
174 _debug_log(
175 _COMMAND_LOGGER,
176 message=_CommandStatusMessage.STARTED,
177 clientId=client._topology_settings._topology_id,
178 command=cmd,
179 commandName=next(iter(cmd)),
180 databaseName=dbn,
181 requestId=request_id,
182 operationId=request_id,
183 driverConnectionId=conn.id,
184 serverConnectionId=conn.server_connection_id,
185 serverHost=conn.address[0],
186 serverPort=conn.address[1],
187 serviceId=conn.service_id,
188 )
189
190 if publish:
191 if "$db" not in cmd:
192 cmd["$db"] = dbn
193 assert listeners is not None
194 listeners.publish_command_start(
195 cmd,

Callers 2

_run_operationMethod · 0.45
_cmdMethod · 0.45

Calls 15

operation_to_commandMethod · 0.95
_split_messageMethod · 0.95
_debug_logFunction · 0.90
_check_command_responseFunction · 0.90
_convert_exceptionFunction · 0.90
_decode_all_selectiveFunction · 0.90
PinnedResponseClass · 0.90
ResponseClass · 0.90
nextFunction · 0.85
iterFunction · 0.85
publish_command_startMethod · 0.80

Tested by

no test coverage detected