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?
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.
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.
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.
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>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With