Retrieve xattrs._sync.rev via n1ql, Java SDK or admin rest api


here is an example meta data of a document:

  "meta": {
    "id": "<my-doc-id>",
    "rev": "39080-15a545e5924b00000000000000000000",
    "expiration": 0,
    "flags": 0,
    "type": "json"
  "xattrs": {
    "_sync": {
      "rev": "61-44fbbf3426fe3eacc2c6565434b5beb4",
      "sequence": 114571699,
      "recent_sequences": [
      "history": {
        "revs": [
        "parents": [
        "channels": [
      "channels": {
        "<my-channel>": null
      "cas": "0x00004b92e545a515",
      "value_crc32c": "0x000ae289",
      "time_saved": "2019-06-05T12:14:58.255792257+02:00"

Is there any way to retrieve xattrs._sync.rev via n1ql, Java SDK or admin rest api? If so could you kindly provide an example?


Hey @benjamin_glatzeder

I’m curious why you need to do this, if you let us know what you need to do with the info we may we able to suggest other approaches.

This (untested, admittedly) Java SDK code should access that data:

        DocumentFragment<Lookup> result = bucket.lookupIn("doc-id")
                .get("_sync.rev", SubdocOptionsBuilder.builder().xattr(true))

        String content = (String) result.content(0);

In N1QL you can see xattrs using the meta() function. It needs to be covered so we need to create an index first. For eg -
create index id2 on default(c1,meta().xattrs._sync,c2).

With the explain we should get -
“expr”: “cover ((meta(default).xattrs._sync))”

select c1,meta().xattrs._sync,c2 from default where c1=5;

Should give something like this -
“_sync”: ,
“c2” : 3

If you need to explicitly select something within _sync you can specify that.
select c1,meta().xattrs._sync.rev,c2 from default where c1=5;

Following this thread: it is recommended to use the SG GET document function to get the revision.

Old post

Thank you @isha and @graham.pople!

I went the n1ql route and the following query returns the latest revision:

SELECT meta().xattrs._sync.rev FROM <my_bucket> USE KEYS '<my_doc_id>';

The goal is to delete an attachment of a document. This SG REST API method [1] does not support removing an attachment but there is an open issue on Github [2]. To update the document and attachment I went with this method [3] which needs a revision as parameter. I believe with the above n1ql query the latest revision of the doc is returned. That is the revision I need to get the job done.



1 Like

i think that required way is the exact way to do that, may be i am wrong!