Hi Nagarajan,
You’ve almost got it. Try this:
public static Optional<String> getSyncGatewayRevision(Collection c,
String documentId) {
try {
LookupInResult result = c.lookupIn(documentId,
singletonList(LookupInSpec.get("_sync.rev").xattr()));
return Optional.of(result.contentAs(0, String.class));
} catch (PathNotFoundException notFound) {
// document doesn't have Sync Gateway revision
return Optional.empty();
}
}
However, I’m not sure if accessing the revision like this is supported. To quote @jens in the SG REST Admin API gives misleading response - #7 by benjamin_glatzeder thread:
the best way to get the revision of a document is to use the SG REST API. Just GET the document and look at the
_rev
property of the response. Or if you’ve just created/updated the document with a PUT, the revision will also be available in the response.
Thanks,
David