How does CouchDB calculate the Revision number

混江龙づ霸主 提交于 2020-01-03 09:10:11

问题


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?


回答1:


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>>



来源:https://stackoverflow.com/questions/5954864/how-does-couchdb-calculate-the-revision-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!