How to find the base parent revision ID of a document in Sync gateway


Is there a way to find the parent version ID of the current document revision through sync gateway public API ?

Curious to know why you want that information.

You could use the GET Document API with revs=true query parameter to get the revision history.

Your resoponse would look something like this -

    "_id": "abc123",
    "_rev": "2-1119627502568566ae5f8fec2289d5d7",
    "_revisions": {
        "ids": [
        "start": 2
    "foo": "bar"

Thank You,

I am using follow library to observe the document changes.
In one of the library’s onChange callback, I want to know the exact change that happened to the document.

Please ref to this issue:

Since this seems to be a long way, would you recommend any better approach other that this ?

You can’t do what you are trying to accomplish using just the parent rev Id.
There isn’t an interface to get specific revision of a document (which in your case is the parent rev Id). Couchbase isn’t intended to be a version control system. The JSON bodies of non-leaf revisions are not guaranteed to exist - the system holds on the metadata of the non-leaf revisions for a certain period (subject to compaction )
If there are conflicts, then you can get the conflicting revisions and try to resolve the conflict. (CC @traun)

Thanks for the reply!

Well, I actually don’t require the entire revision history of a document. My use case is: implementing a document state machine similar to this

In the changes worker pattern I am able to fetch the changes feed through follow library, however, I’m unable to find whether the document state change happened or not. As a workaround, I am fetching the document previous state through revs_info and comparing it with current document to know whether the state change has occurred or not.

So, I just wanted to know is the only way or is there any better approach.

hmm…wondering if it would be easier for you to just include a “state” property within the document that can be used to drive the state machine of your business app. Maybe include “prevState” and “currState” properties and every time you update the document, you set prevState = currState and update currState to new state. Then when you fetch the document, you can use the info from current Doc to drive next state.
Otherwise, you have to track the prev rev and current rev as you proposed …