How do I identify what has changed between document revisions?


#1

I’m writing server side code that consumes the changes feed from the Sync Gateway’s REST API. I can find out when a revision has occurred and get the entire document for that revision. What I need to know is what fields have changed between the document revisions. Does the Sync Gateway provide this information? If not, what is a good strategy to identify what has changed between revisions?

For example, if I have the following document:

{
  "channels": "message",
  "message": {
    "Body": "original message",
    "CreatedAt": "2015-01-30T16:46:07.8864897Z",
  },
  "_rev": "10-83f4bd7f126223a92c12b94678c33770",
  "_id": "0eb2b3cf4276ee732757313594150cc7"
}

Then it changes to the following:

{
  "channels": "message",
  "message": {
    "Body": "updated message",
    "CreatedAt": "2015-01-30T16:46:07.8864897Z",
  },
  "_rev": "11-0d65226361863a177cb16e6ce77bc3d6",
  "_id": "0eb2b3cf4276ee732757313594150cc7"
}

I’ll need to know that message.Body has changed. In my application, the data structure will have more fields and nested objects then this example.


#2

The Sync Gateway doesn’t track changes on a per-property basis. If you need that, you’ll have to compare the revision against its parent and manually identify the diffs.


#3

That makes sense. Thank you @jens!