On May 27, 2009, at 4:05 PM, Brian Candler wrote:
On Wed, May 27, 2009 at 07:41:54PM +0200, Jan Lehnardt wrote:
`GET /db/doc?conflicts=true` gives you a new `_conflicts` member
with an
array value of all conflicting revisions (that you then have to fetch
separately).
I know that - but not only do you have to ask explicitly to be told
that
there are conflicts, you have to fetch each one individually.
Do you mean that something like `include_docs` would be handy here?
Yes. I think the default if you ask for a doc shoule be to get all
versions
of it, not just one arbitrary version.
Here is an example of what I mean, in code.
----- 8< -----
require 'rubygems'
require 'restclient'
require 'json'
require 'pp'
DB="http://127.0.0.1:5984/test"
RestClient.delete DB rescue nil
RestClient.put DB, {}.to_json
doc = {"_id"=>"test","hello"=>"world","_attachments"=>{
"foo"=>{"content_type"=>"text/plain","data"=>["This is a
test"].pack("m").chomp},
"bar"=>{"content_type"=>"text/plain","data"=>["This is
unchanged"].pack("m").chomp},
}}
RestClient.post("#{DB}/_bulk_docs",
{'docs'=>[doc],'all_or_nothing'=>true}.to_json)
doc["_attachments"]["foo"]["data"] = ["This is
change"].pack("m").chomp
RestClient.post("#{DB}/_bulk_docs",
{'docs'=>[doc],'all_or_nothing'=>true}.to_json)
# Problem 1: how to retrieve all conflicting versions of a document
quickly?
# Best I can do is this:
docs = []
res = RestClient.get("#{DB}/test?conflicts=true")
doc = JSON.parse(res)
more_revs = doc.delete('_conflicts')
docs << doc
more_revs.each do |rev|
docs << JSON.parse(RestClient.get("#{DB}/test?rev=#{rev}"))
end
pp docs
# (Note: if you misspell 'conflicts' then it is silently ignored)
# Problem 2: now you have the conflicting versions, how do you tell
which
# of the attachments is different, without downloading them all?
----- 8< -----
You can add an url option attachments=true to get the attachments
inline. We've been wanting to add document and attachment hashes for a
while now, that would be helpful. Also, eventually we'll have
attachment level replication, so we'll know also which revision an
attachment was edited.
You can use revs=all to open all the conflicts (deleted conflicts
too), or just the conflicts revs you want:
http://127.0.0.1:5984/test_suite_db_b/foo?open_revs=all
http://127.0.0.1:5984/test_suite_db_b/foo?open_revs=["2-3945190883",
"3-4948835190"]
The open_revs options might not be documented on the wiki, it would be
nice if someone fixed that.
Also, bulk document retrieval via POST where the post body specifies
the docs and revisions is something we'd like to see added to the
front end too. That could be used by the replicator as well.
Patches welcome, I and others in community will be glad to help you.
-Damien