Wednesday 21 July 2021

ArangoDB: revision: Get the revision id of a collection

Every collection in ArangoDB maintains a revision id (it is a string value). This revision id is updated whenever a document data is modified, either by inserting, deleting, updating or replacing documents in it.

 

Why a collection need revision id?

Revision id can be used by clients to check is there any change in the collection data from previous fetch.

 

Let’s see it with an example.

 

Step 1: Let’s create a database and collection in ArangoDB.

127.0.0.1:8529@_system> db._createDatabase("abc_org")
true

127.0.0.1:8529@_system> db._useDatabase("abc_org")
true

127.0.0.1:8529@abc_org> db._create("user")
[ArangoCollection 12893, "user" (type document, status loaded)]

 

Step 2: Get the revision id of user collection.

127.0.0.1:8529@abc_org> userCollection = db.user
[ArangoCollection 12893, "user" (type document, status loaded)]

127.0.0.1:8529@abc_org> userCollection.revision()
0

Step 3: Let’s add some data to the user collection and get the collection revision.

127.0.0.1:8529@abc_org> userCollection.save({"id" : 1, "firstName": "Ram"})
{ 
  "_id" : "user/12977", 
  "_key" : "12977", 
  "_rev" : "_cRdSijO---" 
}

127.0.0.1:8529@abc_org> userCollection.revision()
1698839237559844864


Step 4: Let’s add another document to user collection and get the revision id again.

127.0.0.1:8529@abc_org> userCollection.save({"id" : 514, "firstName": "Sailu"})
{ 
  "_id" : "user/13028", 
  "_key" : "13028", 
  "_rev" : "_cRdT1TK---" 
}

127.0.0.1:8529@abc_org> userCollection.revision()
1698839326410932224




 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment