MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / mutate_in

Method mutate_in

acouchbase/collection.py:971–1029  ·  view source on GitHub ↗

Performs a mutate-in operation against a document. Allowing atomic modification of specific fields within a document. Also enables access to document extended-attributes (i.e. xattrs). Args: key (str): The key for the document look in. spec (Iterable[:class:`

(self,
                        key,  # type: str
                        spec,  # type: Iterable[Spec]
                        *opts,  # type: MutateInOptions
                        **kwargs,  # type: Any
                        )

Source from the content-addressed store, hash-verified

969 return await self._impl.lookup_in_all_replicas(req, transcoder, obs_handler)
970
971 async def mutate_in(self,
972 key, # type: str
973 spec, # type: Iterable[Spec]
974 *opts, # type: MutateInOptions
975 **kwargs, # type: Any
976 ) -> MutateInResult:
977 """Performs a mutate-in operation against a document. Allowing atomic modification of specific fields
978 within a document. Also enables access to document extended-attributes (i.e. xattrs).
979
980 Args:
981 key (str): The key for the document look in.
982 spec (Iterable[:class:`~couchbase.subdocument.Spec`]): A list of specs describing the operations to
983 perform on the document.
984 opts (:class:`~couchbase.options.MutateInOptions`): Optional parameters for this operation.
985 **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to
986 override provided :class:`~couchbase.options.MutateInOptions`
987
988 Returns:
989 Awaitable[:class:`~couchbase.result.MutateInResult`]: A future that contains an instance
990 of :class:`~couchbase.result.MutateInResult` if successful.
991
992 Raises:
993 :class:`~couchbase.exceptions.DocumentNotFoundException`: If the key provided does not exist
994 on the server.
995
996 Examples:
997
998 Simple mutate-in operation::
999
1000 import couchbase.subdocument as SD
1001
1002 # ... other code ...
1003
1004 bucket = cluster.bucket('travel-sample')
1005 collection = bucket.scope('inventory').collection('hotel')
1006
1007 key = 'hotel_10025'
1008 res = await collection.mutate_in(key, (SD.replace("city", "New City"),))
1009
1010
1011 Simple mutate-in operation with options::
1012
1013 from datetime import timedelta
1014
1015 import couchbase.subdocument as SD
1016 from couchbase.options import MutateInOptions
1017
1018 # ... other code ...
1019
1020 key = 'hotel_10025'
1021 res = await collection.mutate_in(key,
1022 (SD.replace("city", "New City"),),
1023 MutateInOptions(timeout=timedelta(seconds=2)))
1024
1025 """
1026 instruments = self._impl.observability_instruments
1027 async with ObservableRequestHandler.create(KeyValueOperationType.MutateIn, instruments) as obs_handler:
1028 req = self._impl.request_builder.build_mutate_in_request(key, spec, obs_handler, *opts, **kwargs)

Callers 3

removeMethod · 0.45
removeMethod · 0.45
popMethod · 0.45

Calls 2

createMethod · 0.45

Tested by

no test coverage detected