【问题标题】:What is the key and value doing in the Couchbase C SDK’s Hello World example?Couchbase C SDK 的 Hello World 示例中的关键和价值是什么?
【发布时间】:2021-06-24 16:19:35
【问题描述】:

在此链接中:https://docs.couchbase.com/c-sdk/current/hello-world/start-using-sdk.html#hello-couchbase

我在下面看到了这个使用 Couchbase SDK 的代码示例,但是键和值指针代表什么?键应该是文档名称吗?

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);
     

【问题讨论】:

    标签: c couchbase


    【解决方案1】:

    在 Couchbase 中,本身没有“文档名称”。 Couchbase 是键/值数据库,但是当您使用 JSON(大多数用户都这样做)时,它就变成了文档数据库。

    所以,如果你指的是:

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

    这是指具有“my-document”键和{"name": "mike"} JSON 值的文档。以下是 Couchbase UI 的一些屏幕截图,展示了它的外观:

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多