1

我在 Couchbase 中有以下文档:

{
  "id": "ee::brown",
  "type": "ee",
  "firstName": "John",
  "lastName": "Brown",
  "email": "jbown@gmail.com"
}

下面的代码尝试获取 id="ee::brown" 的 lastName 字段

ops := []gocb.LookupInSpec{
   gocb.GetSpec("lastName", &gocb.GetSpecOptions{}),
   }
getResult, err := collection.LookupIn("ee::brown", ops, &gocb.LookupInOptions{})
if err != nil {
  panic(err)
}

var lastName string
err = getResult.ContentAt(0, &lastName)
if err != nil {
   panic(err)
}
fmt.Println(lastName) 

运行此代码会生成以下消息:

Not Found (KEY_ENOENT)

在 Query 工作台中运行以下查询可检索完整文档:

select * from mybucket where id="ee::brown"

还尝试将 IsXttra 字段设置为 true,如下所示,但它也不起作用:

ops := []gocb.LookupInSpec{
    gocb.GetSpec("lastName", &gocb.GetSpecOptions{IsXattr: true}),
}

也找不到 GetSpecOption 的 IsXattr 定义。它是干什么用的?请帮忙!

环境:macOS Catalina 10.15.3 版;go-sdk:导入“github.com/couchbase/gocb/v2”;Couchbase:企业版 6.5.0 build 4960

4

0 回答 0