You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Wayne Conrad <wa...@databill.com> on 2011/02/08 00:25:24 UTC

Atomic update of multiple attachments?

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.

Re: Atomic update of multiple attachments?

Posted by Robert Johnson <ro...@rowanshire.net>.
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"

Does this work for you?

Bob

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.


Re: Atomic update of multiple attachments?

Posted by Robert Newson <ro...@gmail.com>.
There's also the multipart/related upload api (though undocumented, I
think). you can send a doc and 0, 1, or many attachments in a single
PUT call.

On Mon, Feb 7, 2011 at 11:38 PM, Robert Johnson <ro...@rowanshire.net> wrote:
>
> 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?
>
> Bob
>
> 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.
>
>

Re: Atomic update of multiple attachments?

Posted by Robert Newson <ro...@gmail.com>.
You could also use the COPY feature. :)

On Mon, Feb 7, 2011 at 11:59 PM, Wayne Conrad <wa...@databill.com> wrote:
> Bob, One of my needs is that requestors can get the most recent "complete"
> set of attachments, even while a new set is being assembled.  I've no sense
> of what it takes to work with previous version of a document, esp. since (as
> I understand it) replication doesn't transfer old revisions of documents.
>  Do you think your idea can be made to work with this need?
>
> I'm wondering if something can be done that's similar to how we
> create/rename files in Unix.  Can I create a temporary document, load it up
> with attachments, and then rename it?
>
> Wayne
>
> On 02/07/11 16:38, Robert Johnson wrote:
>>
>> 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?
>>
>> Bob
>>
>> 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.
>>
>
>

Re: Atomic update of multiple attachments?

Posted by Randall Leeds <ra...@gmail.com>.
If your attachments are small enough that you can use the inline attachment
API I think you could update them all at once.
http://wiki.apache.org/couchdb/HTTP_Document_API#Inline_Attachments

On Mon, Feb 7, 2011 at 15:59, Wayne Conrad <wa...@databill.com> wrote:

> Bob, One of my needs is that requestors can get the most recent "complete"
> set of attachments, even while a new set is being assembled.  I've no sense
> of what it takes to work with previous version of a document, esp. since (as
> I understand it) replication doesn't transfer old revisions of documents.
>  Do you think your idea can be made to work with this need?
>
> I'm wondering if something can be done that's similar to how we
> create/rename files in Unix.  Can I create a temporary document, load it up
> with attachments, and then rename it?
>
> Wayne
>
>
> On 02/07/11 16:38, Robert Johnson wrote:
>
>>
>> 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?
>>
>> Bob
>>
>> 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.
>>>
>>
>>
>

Re: Atomic update of multiple attachments?

Posted by Wayne Conrad <wa...@databill.com>.
Bob, One of my needs is that requestors can get the most recent 
"complete" set of attachments, even while a new set is being assembled. 
  I've no sense of what it takes to work with previous version of a 
document, esp. since (as I understand it) replication doesn't transfer 
old revisions of documents.  Do you think your idea can be made to work 
with this need?

I'm wondering if something can be done that's similar to how we 
create/rename files in Unix.  Can I create a temporary document, load it 
up with attachments, and then rename it?

Wayne

On 02/07/11 16:38, Robert Johnson wrote:
>
> 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?
>
> Bob
>
> 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.
>


Re: Atomic update of multiple attachments?

Posted by Robert Johnson <ro...@rowanshire.net>.
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?

Bob

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.