couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Johnson <>
Subject Re: Atomic update of multiple attachments?
Date Mon, 07 Feb 2011 23:38:50 GMT

Create your document with attributes "eventual_attachment _count" (set this to the expected
count) and "attachment_count_so_far" (set this to zero).
As you add each attachment, increment "attachment_count_so_far" 

Create a view which only emits when "attachment_count_so_far" = "eventual_attachment _count"

For update:-

Remove docs and decrement "attachment_count_so_far"
Reset "eventual_attachment _count"if necessary
Add new attachments and increment "attachment_count_so_far"

Does this work for you?


On 7 Feb 2011, at 23:25, Wayne Conrad wrote:

> Is there anything I can do to achieve the illusion of atomic update of a set of attachments?
 Here's the effect I'd like:
> For create:
> 1. Create a document.
> 2. Add attachments to it.
> 3. Only now does the document and all of its attachments become visible.
> For update:
> 1. Delete all of the document's attachments.
> 2. Add a new set of attachments to the document.
> 3. Only now does the new set of attachments appear to replace the old.
> I'm using Couchdb 1.0.2 and CouchRest 1.0.1.  I'm not opposed to cheating to achieve
my goal.  Suggestions of "Did you think of doing this-other-thing instead?" are also welcome.

View raw message