Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does CouchDB calculate the Revision number

Tags:

erlang

couchdb

I'm trying to understand how CouchDB calculates the revision id for a document. I notice from the source that it's calculated by this bit of code here:

couch_util:md5(term_to_binary([Deleted, OldStart, OldRev, Body, Atts2]))

And I know that if I create a new empty document with no attachments, CouchDB always gives it a revision of 1-967a00dff5e02add41819138abb3284d which, in decimal is <<150,122,0,223,245,224,42,221,65,129,145,56,171,179,40,77>>.

However, if I type the following into the erlang prompt (false for deleted, 0 for OldStart, 0 for OldRev, an empty body and no attachments):

erlang:md5(term_to_binary([false, 0, 0, [], []])).                   

I always get

<<26,196,244,40,211,149,193,185,214,6,230,61,54,138,62,132>>

back.

So what am I doing wrong here - how can I work out the actual revision that couch generates?

like image 258
kybernetikos Avatar asked May 10 '11 18:05

kybernetikos


People also ask

What is Rev CouchDB?

There is the simple answer: The revision history is transmitted during replication. You can read it here: http://docs.couchdb.org/en/latest/replication/protocol.html#upload-batch-of-changed-documents. Follow this answer to receive notifications.

How do I update files in CouchDB?

Open the Fauxton url:http://127.0.0.1:5984/_utils/ You can also update/ change/ edit your document once you created. Click on the edit option (encircled in red). After clicking, you will get a new page where you can edit your entries. After editing click on the save changes tab and your document will be updated.

Is CouchDB key value?

Like the LevelDB key-value store, CouchDB can store any binary data that is modeled in chaincode (CouchDB attachments are used internally for non-JSON data). As a document object store, CouchDB allows you to store data in JSON format, issue rich queries against your data, and use indexes to support your queries.


1 Answers

After reading the answer to Emit Tuples From Erlang Views In CouchDB I realised that what I was doing wrong was not wrapping the empty proplist for body in a tuple. I'm not sure why couch does that, but that's what the problem was.

erlang:md5(term_to_binary([false, 0, 0, {[]}, []])).

Gives the correct answer

<<150,122,0,223,245,224,42,221,65,129,145,56,171,179,40,77>>

like image 155
kybernetikos Avatar answered Nov 15 '22 18:11

kybernetikos