1

In this link: https://docs.couchbase.com/c-sdk/current/hello-world/start-using-sdk.html#hello-couchbase

I see this code example to use Couchbase SDK below , but what are the key and value pointers representing? Is the key supposed to be the document name?

static void store_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPSTORE *resp)
{
const char *key;
size_t nkey;
uint64_t cas;
lcb_respstore_key(resp, &key, &nkey);
lcb_respstore_cas(resp, &cas);
printf(“status: %s, key: %.*s, CAS: 0x%” PRIx64 “\n”,
lcb_strerror_short(lcb_respstore_status(resp)), (int)nkey, key, cas);
}

lcb_install_callback3(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);

lcb_STATUS rc;
lcb_CMDSTORE *cmd;
const char *collection = NULL, *scope = NULL;
size_t collection_len = 0, scope_len = 0;
const char *key = “my-document”;
const char *value = “{“name”: “mike”}”;
rc = lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
rc = lcb_cmdstore_collection(cmd, scope, scope_len, collection, collection_len);
rc = lcb_cmdstore_key(cmd, key, strlen(key));
rc = lcb_cmdstore_value(cmd, value, strlen(value));
rc = lcb_store(instance, NULL, cmd);
rc = lcb_cmdstore_destroy(cmd);
rc = lcb_wait(instance);
     

1 Answers1

1

In Couchbase, there isn't a "document name" per se. Couchbase is key/value database, but when you use JSON (as most users do), it becomes a document database.

So, if you're referring to:

const char *key = "my-document";
const char *value = "{\"name\": \"mike\"}";

That's referring to a document with a key of "my-document" and a JSON value of {"name": "mike"}. Here's some screenshots of the Couchbase UI showing how that looks:

list of documents in a bucket

editing a specific document

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121