开发者

How does CouchDB calculate the Revision number

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 开发者_StackOverflow社区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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜