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

Method set_add

couchbase/collection.py:1600–1643  ·  view source on GitHub ↗

Add an item to a set if the item does not yet exist. .. warning:: This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseSet.add` instead. Args: key (str): The key for the set document. value (Any):

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

Source from the content-addressed store, hash-verified

1598 return CouchbaseSet(key, self._impl)
1599
1600 def set_add(self,
1601 key: str,
1602 value: Any,
1603 create: Optional[bool] = False,
1604 **kwargs: object
1605 ) -> Optional[OperationResult]:
1606 """Add an item to a set if the item does not yet exist.
1607
1608 .. warning::
1609 This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseSet.add`
1610 instead.
1611
1612 Args:
1613 key (str): The key for the set document.
1614 value (Any): The value to add to the set.
1615 create (bool, optional): Whether the set should be created if it does not exist.
1616 **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters
1617 for this operation.
1618
1619 Returns:
1620 :class:`~couchbase.result.OperationResult`: An instance of :class:`~couchbase.result.OperationResult`.
1621
1622 Raises:
1623 :class:`~couchbase.exceptions.DocumentNotFoundException`: If the key provided does not exist
1624 on the server.
1625 """
1626 op_type = DatastructureOperationType.SetAdd
1627 with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler:
1628 ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict())
1629 kv_op_type = KeyValueOperationType.MutateIn
1630 with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler:
1631 op = array_addunique('', value)
1632 try:
1633 req = self._impl.request_builder.build_mutate_in_request(key, (op,), obs_handler, **kwargs)
1634 sd_res = self._execute_deprecated_ds_func(self._impl.mutate_in,
1635 req,
1636 obs_handler,
1637 ds_obs_handler.wrapped_span,
1638 create=create,
1639 create_type=list,
1640 path_value=value)
1641 return OperationResult(sd_res.cas, sd_res.mutation_token())
1642 except PathExistsException:
1643 pass
1644
1645 def set_remove(self, key: str, value: Any, **kwargs: object) -> Optional[OperationResult]:
1646 """Remove an item from a set.

Callers 1

test_setsMethod · 0.80

Calls 8

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

Tested by 1

test_setsMethod · 0.64