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

Update
Following this thread: https://www.couchbase.com/forums/t/sg-rest-admin-api-gives-misleading-response/21823 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] https://docs.couchbase.com/sync-gateway/current/admin-rest-api.html#/attachment/put__db___doc___attachment_
[2] https://github.com/couchbase/sync_gateway/issues/1648
[3] https://docs.couchbase.com/sync-gateway/current/admin-rest-api.html#/document/put__db___doc_

Thanks!

1 Like