1

下面的寄存器结构捕获来自注册 UI 的数据:

register struct {
   Email string
   Password string }

collection.insert 命令创建以下文档:

{  "id": "1",
   "email" : "john@example.com",
   "password" : "pwd"
}

人口统计结构捕获来自人口统计 UI 的数据:

demographics struct {
    Name string
   Address string
}

我想更新文档,所以生成的文档如下:

 { "id": "1",
      "email" : "john@example.com",
      "password": "pwd",
      "name" : "John Doe",
      "address" : "100 Main Street"
    }

使用 N1QL 我可以编写以下内容:

Update bucket set name="John Doe", address="100 Main Street" where id="1"

我在 GO SDK 中找不到更新 API。

4

1 回答 1

3

我不是 Go 开发人员,但我认为您正在寻找的是Couchbase 中的“子文档”操作(它在所有 Couchbase SDK 中都可用,包括 Go)

也就是说,能够插入/更新/删除文档的某些部分,而无需跨网络移动整个内容。例如,这是一个向文档添加“传真”字段的片段(upsert 根据需要创建或替换该字段):

bucket.MutateIn("customer123", 0, 0).Upsert("fax", "311-555-0151", true).Execute()

有许多子文档选项:插入、替换、存在、arrayappend、arrayprepend 等。

于 2020-01-27T15:18:38.857 回答