2

Whats the exact algorithm to calculate the CouchDB revision number. CouchDB uses a deterministic algorithm to calculate the document revision number. Here is one relevant doc I found: https://stackoverflow.com/questions/5954864/how-does-couchdb-calculate-the-revision-number

Buts its all in elrang, I am trying to implement it in dart. I use sample document : {"_id":"123-this-is-an-id","hello":"world","testing":123} for testing.

When I do the MD5 hash of it , its gives me : f0853833850bce08dce0896e010a375e, where as the couchdb revision number is :

"_rev": "1-43dce8fe7e9a26b49390e3727a015cc0"

I google it everywhere, but if I can find the algorithm some where in text , UI can convert it into dart.

gdelfino
  • 103
  • 3
user3769778
  • 121
  • 2

2 Answers2

1

The algorithm is Erlang-specific as it involves the Erlang External Term Format. (CouchDB is written in Erlang.) It would be hard to re-implement in a different language.

It is indeed an MD5 hash, of a binary term representation of the document and its attributes.

I am unsure if the code can be reproduced, so you can find it in the couchdb repository. Note that for the main branch, the new_revid function moved to the Fabric DB implementation.

PouchDB has an entirely different hashing algorithm - its revs are MD5 hashes of the JSON representation of the document without its revision field.

So as you can see, it is not critical to reproduce the algorithm perfectly - you will only run into conflicts when syncing two databases on different platforms that both create docs. And even then, the conflict resolution algorithm should take care of it.

0

So after some time, I got to know that couchdb calculates revision number as such:

seq_num-md5HashOfDocJsonContentWithoutRevField
user3769778
  • 121
  • 2