1

I have the following document in Couchbase:

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

The code below tries to get the lastName field for id="ee::brown"

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) 

Running this code generates the following message:

Not Found (KEY_ENOENT)

Running following query in Query workbench retrieves the full document:

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

Also tried setting IsXttra field to true as follows but it did not work either:

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

Also could not find definition of IsXattr for GetSpecOption. What is it for? Help please!

Environment: macOS Catalina version 10.15.3; go-sdk : import "github.com/couchbase/gocb/v2" ; Couchbase: Enterprise Edition 6.5.0 build 4960

Tusshu
  • 1,664
  • 3
  • 16
  • 32
  • xattr is a kind of generic meta data; I would recommend not using them unless you have a framework-level purpose (Sync Gateway and ACID transactions, for instance, are using xattr to coordinate data) – Matthew Groves Jan 31 '20 at 17:00
  • A clarifying question/note. You show your document with an "id" field. An "id" field within a document is not the same as the document's key. Are you sure your document key has the same value as the "id" field in your document? If not, that would explain a "not found". – Matthew Groves Jan 31 '20 at 17:01
  • Document is created with following command: _, err := cbase.Collection.Insert(id, document, &opt) where id is "ee::brown" and id is also a field in the document with same value. I can get the record with query << select * from mybucket where id="ee::brown" >> in query editor. For some reason, collection.LookupIn cannot find it. – Tusshu Jan 31 '20 at 20:14

0 Answers0