Couchbase C Client  3.3.12
Asynchronous C Client for Couchbase

Detailed Description

Set the value of a document

Function Documentation

◆ lcb_cmdstore_on_behalf_of()

lcb_STATUS lcb_cmdstore_on_behalf_of ( lcb_CMDSTORE * cmd,
const char * data,
size_t data_len )
Internal: This should never be used and is not supported.

◆ lcb_cmdstore_on_behalf_of_extra_privilege()

lcb_STATUS lcb_cmdstore_on_behalf_of_extra_privilege ( lcb_CMDSTORE * cmd,
const char * privilege,
size_t privilege_len )
Internal: This should never be used and is not supported.

Typedef Documentation


typedef struct lcb_RESPSTORE_ lcb_RESPSTORE

Schedule a single storage request.

instancethe handle
cookiepointer to associate with the command
cmdthe command structure
LCB_SUCCESS on success, error code on failure


lcb_CMDSTORE* cmd;
// insert only if key doesn't already exist
lcb_cmdstore_create(&cmd, LCB_STORE_INSERT);
lcb_cmdstore_key(cmd, "Key", 3);
lcb_cmdstore_value(cmd, "value", 5);
lcb_cmdstore_expiry(cmd, 60); // expire in a minute
lcb_store(instance, cookie, &cmd);
Will cause the operation to fail if the key already exists in the cluster.
Definition couchbase.h:893
lcb_STATUS lcb_wait(lcb_INSTANCE *instance, lcb_WAITFLAGS flags)
Wait for completion of scheduled operations.
Do not check pending operations before running the event loop.
Definition couchbase.h:1863


lcb_install_callback(instance, LCB_CALLBACK_STORE, store_callback);
void store_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPBASE *rb)
uint64_t cas;
const lcb_RESPSTORE resp = (const lcb_RESPSTORE*)rb;
lcb_STATUS rc = lcb_respstore_status(resp);
if (rc == LCB_SUCCESS) {
lcb_respstore_cas(resp, &cas)
printf("Store success: CAS=%llx\n", cas);
} else {
printf("Store failed: %s\n", lcb_strerror_short(rc);
LCB_INTERNAL_API const char * lcb_strerror_short(lcb_STATUS error)
Get a shorter textual description of an error message.
Error codes returned by the library.
Definition error.h:212
struct lcb_st lcb_INSTANCE
Library handle representing a connection to a cluster and its data buckets.
Definition couchbase.h:35
lcb_RESPCALLBACK lcb_install_callback(lcb_INSTANCE *instance, int cbtype, lcb_RESPCALLBACK cb)
Definition couchbase.h:472
Schedule a single storage request.
Definition couchbase.h:971

Operation-specific error codes include:

  • ::LCB_ERR_DOCUMENT_NOT_FOUND if ::LCB_REPLACE was used and the key does not exist
  • ::LCB_ERR_DOCUMENT_EXISTS if ::LCB_INSERT was used and the key already exists
  • ::LCB_ERR_DOCUMENT_EXISTS if the CAS was specified (for an operation other than ::LCB_INSERT) and the item exists on the server with a different CAS
  • ::LCB_ERR_DOCUMENT_EXISTS if the item was locked and the CAS supplied did not match the locked item's CAS (or if no CAS was supplied)
  • ::LCB_ERR_NOT_STORED if an ::LCB_APPEND or ::LCB_PREPEND operation was performed and the item did not exist on the server.
  • ::LCB_ERR_VALUE_TOO_LARGE if the size of the value exceeds the cluster per-item value limit (currently 20MB).

For a 6.5 or later cluster, you should use the lcb_cmdstore_durability to make the lcb_store not return until the requested durabilty is met. If the cluster is an older version, you can use lcb_cmdstore_durability_observe.

Enumeration Type Documentation


Values for lcb_CMDSTORE::operation.

Storing an item in couchbase is only one operation with a different set of attributes / constraints.


The default storage mode.

This constant was added in version 2.6.2 for the sake of maintaining a default storage mode, eliminating the need for simple storage operations to explicitly define lcb_CMDSTORE::operation. Behaviorally it is identical to LCB_STORE_UPSERT in that it will make the server unconditionally store the item, whether it exists or not.


Will cause the operation to fail if the key already exists in the cluster.


Will cause the operation to fail unless the key already exists in the cluster.


Rather than setting the contents of the entire document, take the value specified in lcb_CMDSTORE::value and append it to the existing bytes in the value.


Like LCB_STORE_APPEND, but prepends the new value to the existing value.