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

Function _merge_command

pymongo/_client_bulk_shared.py:28–57  ·  view source on GitHub ↗

Merge result of a single bulk write batch into the full result.

(
    ops: list[tuple[str, Mapping[str, Any]]],
    offset: int,
    full_result: MutableMapping[str, Any],
    result: Mapping[str, Any],
)

Source from the content-addressed store, hash-verified

26
27
28def _merge_command(
29 ops: list[tuple[str, Mapping[str, Any]]],
30 offset: int,
31 full_result: MutableMapping[str, Any],
32 result: Mapping[str, Any],
33) -> None:
34 """Merge result of a single bulk write batch into the full result."""
35 if result.get("error"):
36 full_result["error"] = result["error"]
37
38 full_result["nInserted"] += result.get("nInserted", 0)
39 full_result["nDeleted"] += result.get("nDeleted", 0)
40 full_result["nMatched"] += result.get("nMatched", 0)
41 full_result["nModified"] += result.get("nModified", 0)
42 full_result["nUpserted"] += result.get("nUpserted", 0)
43
44 write_errors = result.get("writeErrors")
45 if write_errors:
46 for doc in write_errors:
47 # Leave the server response intact for APM.
48 replacement = doc.copy()
49 original_index = doc["idx"] + offset
50 replacement["idx"] = original_index
51 # Add the failed operation to the error document.
52 replacement["op"] = ops[original_index][1]
53 full_result["writeErrors"].append(replacement)
54
55 wce = _get_wce_doc(result)
56 if wce:
57 full_result["writeConcernErrors"].append(wce)
58
59
60def _throw_client_bulk_write_exception(

Callers 2

_execute_commandMethod · 0.90
_execute_commandMethod · 0.90

Calls 3

_get_wce_docFunction · 0.90
copyMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected