0

I want to update xattr in meta of a document. I didnt find any document provided by couchbase.

{
  "meta": {
    "id": "0000c84b-e2bc-43ac-af51-7cf141777f49",
    "rev": "102-163756db3f7100000000000002000000",
    "expiration": 0,
    "flags": 33554432,
    "type": "json"
  },
  "xattrs": {}
}

Can anyone help me.

Amit Sinha
  • 566
  • 7
  • 22

1 Answers1

1

To update XATTR, use the Sub-Document API. Here's an example from the Couchbase Java documentation:

JsonObject docContent = JsonObject.create().put("body", "value");
collection.mutateIn("hotel_14006",
    Arrays.asList(MutateInSpec.upsert("foo", "bar").xattr().createPath(), MutateInSpec.replace("", docContent)));

Notice the use of .xattr().

Note that XATTR's generally should only be used for framework/library metadata, and are not meant for use in general applications. XATTRs may not be accessible by all Couchbase services (Search, for example).

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
  • 2
    can you please help me how can we read it. For meta we can read but if we are trying to read xattrs like meta, it is not working. – Amit Sinha May 31 '23 at 21:48
  • 2
    @AmitSinha com.couchbase.client.java.kv.LookupInMacro will give you access to those fields. DOCUMENT in particular will give you everything - or you can lookup specific fields if you need. – Graham Pople Jun 01 '23 at 11:09