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

Method write_command

pymongo/synchronous/client_bulk.py:229–318  ·  view source on GitHub ↗

A proxy for Connection.write_command that handles event publishing.

(
        self,
        bwc: _ClientBulkWriteContext,
        cmd: MutableMapping[str, Any],
        request_id: int,
        msg: Union[bytes, dict[str, Any]],
        op_docs: list[Mapping[str, Any]],
        ns_docs: list[Mapping[str, Any]],
        client: MongoClient[Any],
    )

Source from the content-addressed store, hash-verified

227
228 @_handle_reauth
229 def write_command(
230 self,
231 bwc: _ClientBulkWriteContext,
232 cmd: MutableMapping[str, Any],
233 request_id: int,
234 msg: Union[bytes, dict[str, Any]],
235 op_docs: list[Mapping[str, Any]],
236 ns_docs: list[Mapping[str, Any]],
237 client: MongoClient[Any],
238 ) -> dict[str, Any]:
239 """A proxy for Connection.write_command that handles event publishing."""
240 cmd["ops"] = op_docs
241 cmd["nsInfo"] = ns_docs
242 if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
243 _debug_log(
244 _COMMAND_LOGGER,
245 message=_CommandStatusMessage.STARTED,
246 clientId=client._topology_settings._topology_id,
247 command=cmd,
248 commandName=next(iter(cmd)),
249 databaseName=bwc.db_name,
250 requestId=request_id,
251 operationId=request_id,
252 driverConnectionId=bwc.conn.id,
253 serverConnectionId=bwc.conn.server_connection_id,
254 serverHost=bwc.conn.address[0],
255 serverPort=bwc.conn.address[1],
256 serviceId=bwc.conn.service_id,
257 )
258 if bwc.publish:
259 bwc._start(cmd, request_id, op_docs, ns_docs)
260 try:
261 reply = bwc.conn.write_command(request_id, msg, bwc.codec) # type: ignore[misc, arg-type]
262 duration = datetime.datetime.now() - bwc.start_time
263 if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
264 _debug_log(
265 _COMMAND_LOGGER,
266 message=_CommandStatusMessage.SUCCEEDED,
267 clientId=client._topology_settings._topology_id,
268 durationMS=duration,
269 reply=reply,
270 commandName=next(iter(cmd)),
271 databaseName=bwc.db_name,
272 requestId=request_id,
273 operationId=request_id,
274 driverConnectionId=bwc.conn.id,
275 serverConnectionId=bwc.conn.server_connection_id,
276 serverHost=bwc.conn.address[0],
277 serverPort=bwc.conn.address[1],
278 serviceId=bwc.conn.service_id,
279 )
280 if bwc.publish:
281 bwc._succeed(request_id, reply, duration) # type: ignore[arg-type]
282 # Process the response from the server.
283 self.client._process_response(reply, bwc.session) # type: ignore[arg-type]
284 except Exception as exc:
285 duration = datetime.datetime.now() - bwc.start_time
286 if isinstance(exc, (NotPrimaryError, OperationFailure)):

Callers 1

_execute_batchMethod · 0.95

Calls 8

_debug_logFunction · 0.90
_convert_exceptionFunction · 0.90
nextFunction · 0.85
iterFunction · 0.85
_succeedMethod · 0.80
_failMethod · 0.80
_startMethod · 0.45
_process_responseMethod · 0.45

Tested by

no test coverage detected