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

Method write_command

pymongo/asynchronous/bulk.py:244–327  ·  view source on GitHub ↗

A proxy for SocketInfo.write_command that handles event publishing.

(
        self,
        bwc: _BulkWriteContext,
        cmd: MutableMapping[str, Any],
        request_id: int,
        msg: bytes,
        docs: list[Mapping[str, Any]],
        client: AsyncMongoClient[Any],
    )

Source from the content-addressed store, hash-verified

242
243 @_handle_reauth
244 async def write_command(
245 self,
246 bwc: _BulkWriteContext,
247 cmd: MutableMapping[str, Any],
248 request_id: int,
249 msg: bytes,
250 docs: list[Mapping[str, Any]],
251 client: AsyncMongoClient[Any],
252 ) -> dict[str, Any]:
253 """A proxy for SocketInfo.write_command that handles event publishing."""
254 cmd[bwc.field] = docs
255 if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
256 _debug_log(
257 _COMMAND_LOGGER,
258 message=_CommandStatusMessage.STARTED,
259 clientId=client._topology_settings._topology_id,
260 command=cmd,
261 commandName=next(iter(cmd)),
262 databaseName=bwc.db_name,
263 requestId=request_id,
264 operationId=request_id,
265 driverConnectionId=bwc.conn.id,
266 serverConnectionId=bwc.conn.server_connection_id,
267 serverHost=bwc.conn.address[0],
268 serverPort=bwc.conn.address[1],
269 serviceId=bwc.conn.service_id,
270 )
271 if bwc.publish:
272 bwc._start(cmd, request_id, docs)
273 try:
274 reply = await bwc.conn.write_command(request_id, msg, bwc.codec) # type: ignore[misc]
275 duration = datetime.datetime.now() - bwc.start_time
276 if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
277 _debug_log(
278 _COMMAND_LOGGER,
279 message=_CommandStatusMessage.SUCCEEDED,
280 clientId=client._topology_settings._topology_id,
281 durationMS=duration,
282 reply=reply,
283 commandName=next(iter(cmd)),
284 databaseName=bwc.db_name,
285 requestId=request_id,
286 operationId=request_id,
287 driverConnectionId=bwc.conn.id,
288 serverConnectionId=bwc.conn.server_connection_id,
289 serverHost=bwc.conn.address[0],
290 serverPort=bwc.conn.address[1],
291 serviceId=bwc.conn.service_id,
292 )
293 if bwc.publish:
294 bwc._succeed(request_id, reply, duration) # type: ignore[arg-type]
295 await client._process_response(reply, bwc.session) # type: ignore[arg-type]
296 except Exception as exc:
297 duration = datetime.datetime.now() - bwc.start_time
298 if isinstance(exc, (NotPrimaryError, OperationFailure)):
299 failure: _DocumentOut = exc.details # type: ignore[assignment]
300 else:
301 failure = _convert_exception(exc)

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