如何使用GO SDK在Couchbase文档中添加新字段

如何使用GO SDK在Couchbase文档中添加新字段,go,couchbase,go-couchbase,Go,Couchbase,Go Couchbase,下面的注册结构捕获来自注册UI的数据: register struct { Email string Password string } collection.insert命令创建以下文档: { "id": "1", "email" : "john@example.com", "password" : "pwd" } 人口统计结构捕获来自人口统计UI的数据: demographics struct { Name string Address strin

下面的注册结构捕获来自注册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

我不是Go开发者,但我认为您正在寻找的是Couchbase,它在所有Couchbase SDK中都可用,包括Go

也就是说,能够插入/更新/删除文档的一部分,而无需将整个文档跨线移动。例如,这里有一个向文档中添加传真字段的代码段,upsert会根据需要创建或替换该字段:

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

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

我不是Go开发者,但我认为您需要的是Couchbase中的,它在所有Couchbase SDK中都可用,包括Go

也就是说,能够插入/更新/删除文档的一部分,而无需将整个文档跨线移动。例如,这里有一个向文档中添加传真字段的代码段,upsert会根据需要创建或替换该字段:

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

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

太棒了!很高兴你让它工作了。正在将Go添加到我的简历中:-PGreat!很高兴你让它工作了。正在将Go添加到我的简历中:-P