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

Method _update

pymongo/synchronous/collection.py:977–1071  ·  view source on GitHub ↗

Internal update / replace helper.

(
        self,
        conn: Connection,
        criteria: Mapping[str, Any],
        document: Union[Mapping[str, Any], _Pipeline],
        upsert: bool = False,
        multi: bool = False,
        write_concern: Optional[WriteConcern] = None,
        op_id: Optional[int] = None,
        ordered: bool = True,
        bypass_doc_val: Optional[bool] = None,
        collation: Optional[_CollationIn] = None,
        array_filters: Optional[Sequence[Mapping[str, Any]]] = None,
        hint: Optional[_IndexKeyHint] = None,
        session: Optional[ClientSession] = None,
        retryable_write: bool = False,
        let: Optional[Mapping[str, Any]] = None,
        sort: Optional[Mapping[str, Any]] = None,
        comment: Optional[Any] = None,
    )

Source from the content-addressed store, hash-verified

975 return InsertManyResult(inserted_ids, write_concern.acknowledged)
976
977 def _update(
978 self,
979 conn: Connection,
980 criteria: Mapping[str, Any],
981 document: Union[Mapping[str, Any], _Pipeline],
982 upsert: bool = False,
983 multi: bool = False,
984 write_concern: Optional[WriteConcern] = None,
985 op_id: Optional[int] = None,
986 ordered: bool = True,
987 bypass_doc_val: Optional[bool] = None,
988 collation: Optional[_CollationIn] = None,
989 array_filters: Optional[Sequence[Mapping[str, Any]]] = None,
990 hint: Optional[_IndexKeyHint] = None,
991 session: Optional[ClientSession] = None,
992 retryable_write: bool = False,
993 let: Optional[Mapping[str, Any]] = None,
994 sort: Optional[Mapping[str, Any]] = None,
995 comment: Optional[Any] = None,
996 ) -> Optional[Mapping[str, Any]]:
997 """Internal update / replace helper."""
998 validate_boolean("upsert", upsert)
999 collation = validate_collation_or_none(collation)
1000 write_concern = write_concern or self.write_concern
1001 acknowledged = write_concern.acknowledged
1002 update_doc: dict[str, Any] = {
1003 "q": criteria,
1004 "u": document,
1005 "multi": multi,
1006 "upsert": upsert,
1007 }
1008 if collation is not None:
1009 if not acknowledged:
1010 raise ConfigurationError("Collation is unsupported for unacknowledged writes.")
1011 else:
1012 update_doc["collation"] = collation
1013 if array_filters is not None:
1014 if not acknowledged:
1015 raise ConfigurationError("arrayFilters is unsupported for unacknowledged writes.")
1016 else:
1017 update_doc["arrayFilters"] = array_filters
1018 if hint is not None:
1019 if not acknowledged and conn.max_wire_version < 8:
1020 raise ConfigurationError(
1021 "Must be connected to MongoDB 4.2+ to use hint on unacknowledged update commands."
1022 )
1023 if not isinstance(hint, str):
1024 hint = helpers_shared._index_document(hint)
1025 update_doc["hint"] = hint
1026 if sort is not None:
1027 if not acknowledged and conn.max_wire_version < 25:
1028 raise ConfigurationError(
1029 "Must be connected to MongoDB 8.0+ to use sort on unacknowledged update commands."
1030 )
1031 common.validate_is_mapping("sort", sort)
1032 update_doc["sort"] = sort
1033
1034 command = {"update": self.name, "ordered": ordered, "updates": [update_doc]}

Callers

nothing calls this directly

Calls 7

validate_booleanFunction · 0.90
ConfigurationErrorClass · 0.90
copyMethod · 0.80
commandMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected