couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <>
Subject Re: struggling with couchdb in production
Date Wed, 27 May 2009 20:05:00 GMT
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'

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},
}}"#{DB}/_bulk_docs", {'docs'=>[doc],'all_or_nothing'=>true}.to_json)
doc["_attachments"]["foo"]["data"] = ["This is change"].pack("m").chomp"#{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}"))

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



View raw message