Reputation: 1131
I see the _rev
in every document created in ArangoDB, but I have yet to see any information about using those revisions to access the change history for a document. More specifically, how do I query the revision history for a specific document to see the previous versions or even a specific version in time?
Upvotes: 2
Views: 1892
Reputation: 2349
My understanding is that the revision (_rev
) attribute is just there as a marker so you can know when a field was updated. You can't change it directly, but every time you UPDATE
a document in a collection, the _rev
value is updated.
To store historical values you would need to implement a process to archive the old values of a document when they get updated.
The _rev
attribute can be very helpful when scanning a document and seeing if any values were changed. Rather than having to do a deep compare on a document and what you expect to see, you can just compare the _rev
attribute with what you expect to see. If the database returns a different _rev
value than what you were checking for then your code can respond to the document changing, however required.
Remember, you have access to the old version of a document when you execute an UPDATE
or UPSERT
command (the doco) and you could choose to return the OLD
document contents to push off to an archive location, or process as you wish. The updated document will receive a new _rev
value after that update.
The OLD
value does not persist after the return of the UPDATE
or UPSERT
command, so you'll have to archive it right away or the older document will be lost.
Upvotes: 5