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

Method map_add

couchbase/collection.py:1438–1481  ·  view source on GitHub ↗

Set a value for a key in a map. .. warning:: This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseMap.add` instead. Args: key (str): The key for the map document. mapkey (str): The key in the map t

(self,
                key: str,
                mapkey: str,
                value: Any,
                create: Optional[bool] = False,
                **kwargs: object
                )

Source from the content-addressed store, hash-verified

1436 return CouchbaseMap(key, self._impl)
1437
1438 def map_add(self,
1439 key: str,
1440 mapkey: str,
1441 value: Any,
1442 create: Optional[bool] = False,
1443 **kwargs: object
1444 ) -> OperationResult:
1445 """Set a value for a key in a map.
1446
1447 .. warning::
1448 This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseMap.add`
1449 instead.
1450
1451 Args:
1452 key (str): The key for the map document.
1453 mapkey (str): The key in the map to set.
1454 value (Any): The value to use.
1455 create (bool, optional): Whether the map should be created if it does not exist.
1456 **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters
1457 for this operation.
1458
1459 Returns:
1460 :class:`~couchbase.result.OperationResult`: An instance of :class:`~couchbase.result.OperationResult`.
1461
1462 Raises:
1463 :class:`~couchbase.exceptions.DocumentNotFoundException`: If the key provided does not exist
1464 on the server.
1465
1466 """
1467 op_type = DatastructureOperationType.MapAdd
1468 with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler:
1469 ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict())
1470 kv_op_type = KeyValueOperationType.MutateIn
1471 with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler:
1472 op = subdoc_upsert(mapkey, value)
1473 req = self._impl.request_builder.build_mutate_in_request(key, (op,), obs_handler, **kwargs)
1474 sd_res = self._execute_deprecated_ds_func(self._impl.mutate_in,
1475 req,
1476 obs_handler,
1477 ds_obs_handler.wrapped_span,
1478 create=create,
1479 create_type=dict,
1480 path_value=mapkey)
1481 return OperationResult(sd_res.cas, sd_res.mutation_token())
1482
1483 def map_get(self, key: str, mapkey: str, **kwargs: object) -> Any:
1484 """Retrieve a value from a map.

Callers 1

test_mapMethod · 0.80

Calls 7

OperationResultClass · 0.90
get_details_as_dictMethod · 0.80
create_kv_spanMethod · 0.45
mutation_tokenMethod · 0.45

Tested by 1

test_mapMethod · 0.64