如何在ArangoDB中查询修订历史记录?

时间:2017-04-09 22:35:16

标签: graph-databases arangodb aql nosql

我在ArangoDB中创建的每个文档中都看到_rev,但我还没有看到有关使用这些修订来访问文档更改历史记录的任何信息。更具体地说,如何查询特定文档的修订历史记录以查看以前的版本甚至是特定版本?

1 个答案:

答案 0 :(得分:3)

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.