You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Daniel Gonzalez <go...@gonvaled.com> on 2013/12/05 07:04:57 UTC

What would be the best way to exactly duplicate a document, with attachments?

Hi all,

Let's say I have host1/db1/doc_id1 which I want to duplicate to
host2/db2/doc_id2.

The original document has (maybe) attachments. Currently what I am doing is:

1.
Get doc1. I get an attachment stub.
2.
Put this document to host2/db2/doc_id2
3.
Now I should loop through all attachments, get them, and put them to the
new document. Probably something will not be guesses right (content_type,
...).

Instead, I would like to use a method which:

1.
Duplicates the document by using a single GET to obtain the original
documents + attachments, and creates the new document with a single
PUT/POST (is this possible, no matter the amount of attachments?)
2.
Does not use the filesystem to save the attachments
3.
Does not use replication
4.
Does not recreate the attachments: specifically, no re-guessing of the
content type and other attachment properties.
To make it clear: I want an exact copy of the original document, except
that:

1.
The doc_id is different
2.
It is in a different host/database than the original document
3.
There is no revision

Is there any built-in couchdb support for this?

Thanks,
Daniel


Link to original SO question: http://stackoverflow.com/q/20386913/647991

Re: What would be the best way to exactly duplicate a document, with attachments?

Posted by Robert Newson <rn...@apache.org>.
https://wiki.apache.org/couchdb/Replication#Named_Document_Replication ?

On 5 December 2013 08:10, Benoit Chesneau <bc...@gmail.com> wrote:
> this not really possible diectly for now.
>
>
> maybe copy to a new doc id, replicate this docid  and delete on the source?
>
> (why renaming on the other host?)
>
> On Thursday, December 5, 2013, Daniel Gonzalez wrote:
>
>> Hi all,
>>
>> Let's say I have host1/db1/doc_id1 which I want to duplicate to
>> host2/db2/doc_id2.
>>
>> The original document has (maybe) attachments. Currently what I am doing
>> is:
>>
>> 1.
>> Get doc1. I get an attachment stub.
>> 2.
>> Put this document to host2/db2/doc_id2
>> 3.
>> Now I should loop through all attachments, get them, and put them to the
>> new document. Probably something will not be guesses right (content_type,
>> ...).
>>
>> Instead, I would like to use a method which:
>>
>> 1.
>> Duplicates the document by using a single GET to obtain the original
>> documents + attachments, and creates the new document with a single
>> PUT/POST (is this possible, no matter the amount of attachments?)
>> 2.
>> Does not use the filesystem to save the attachments
>> 3.
>> Does not use replication
>> 4.
>> Does not recreate the attachments: specifically, no re-guessing of the
>> content type and other attachment properties.
>> To make it clear: I want an exact copy of the original document, except
>> that:
>>
>> 1.
>> The doc_id is different
>> 2.
>> It is in a different host/database than the original document
>> 3.
>> There is no revision
>>
>> Is there any built-in couchdb support for this?
>>
>> Thanks,
>> Daniel
>>
>>
>> Link to original SO question: http://stackoverflow.com/q/20386913/647991
>>

Re: What would be the best way to exactly duplicate a document, with attachments?

Posted by Benoit Chesneau <bc...@gmail.com>.
this not really possible diectly for now.


maybe copy to a new doc id, replicate this docid  and delete on the source?

(why renaming on the other host?)

On Thursday, December 5, 2013, Daniel Gonzalez wrote:

> Hi all,
>
> Let's say I have host1/db1/doc_id1 which I want to duplicate to
> host2/db2/doc_id2.
>
> The original document has (maybe) attachments. Currently what I am doing
> is:
>
> 1.
> Get doc1. I get an attachment stub.
> 2.
> Put this document to host2/db2/doc_id2
> 3.
> Now I should loop through all attachments, get them, and put them to the
> new document. Probably something will not be guesses right (content_type,
> ...).
>
> Instead, I would like to use a method which:
>
> 1.
> Duplicates the document by using a single GET to obtain the original
> documents + attachments, and creates the new document with a single
> PUT/POST (is this possible, no matter the amount of attachments?)
> 2.
> Does not use the filesystem to save the attachments
> 3.
> Does not use replication
> 4.
> Does not recreate the attachments: specifically, no re-guessing of the
> content type and other attachment properties.
> To make it clear: I want an exact copy of the original document, except
> that:
>
> 1.
> The doc_id is different
> 2.
> It is in a different host/database than the original document
> 3.
> There is no revision
>
> Is there any built-in couchdb support for this?
>
> Thanks,
> Daniel
>
>
> Link to original SO question: http://stackoverflow.com/q/20386913/647991
>

Re: What would be the best way to exactly duplicate a document, with attachments?

Posted by Jens Alfke <je...@couchbase.com>.
On Dec 4, 2013, at 11:46 PM, Daniel Gonzalez <go...@gonvaled.com> wrote:

> I have remembered that I can get all attachments (no stubs) at once with
> attachments=true, and that is exactly what I need.

Yup. I can’t recall if that returns JSON or MIME-multipart by default; if the former, try adding a request header “Accept: multipart/*” to get the more compact multipart format.

—Jens

Re: What would be the best way to exactly duplicate a document, with attachments?

Posted by Daniel Gonzalez <go...@gonvaled.com>.
Thanks,

That is interesting, but it will not allow me to copy to another
server/database.

I have remembered that I can get all attachments (no stubs) at once with
attachments=true, and that is exactly what I need.

BR,
Daniel


On Thu, Dec 5, 2013 at 8:25 AM, Garren Smith <ga...@apache.org> wrote:

> Hi Daniel,
>
> You can use the copy API, that should duplicate the document for you. See
> the docs for more
> http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
>
> Cheers
> Garren
>
> On 05 December 2013 at 8:07:04 AM, Daniel Gonzalez (gonvaled@gonvaled.com<//...@gonvaled.com>)
> wrote:
>
> Hi all,
>
> Let's say I have host1/db1/doc_id1 which I want to duplicate to
> host2/db2/doc_id2.
>
> The original document has (maybe) attachments. Currently what I am doing
> is:
>
> 1.
> Get doc1. I get an attachment stub.
> 2.
> Put this document to host2/db2/doc_id2
> 3.
> Now I should loop through all attachments, get them, and put them to the
> new document. Probably something will not be guesses right (content_type,
> ...).
>
> Instead, I would like to use a method which:
>
> 1.
> Duplicates the document by using a single GET to obtain the original
> documents + attachments, and creates the new document with a single
> PUT/POST (is this possible, no matter the amount of attachments?)
> 2.
> Does not use the filesystem to save the attachments
> 3.
> Does not use replication
> 4.
> Does not recreate the attachments: specifically, no re-guessing of the
> content type and other attachment properties.
> To make it clear: I want an exact copy of the original document, except
> that:
>
> 1.
> The doc_id is different
> 2.
> It is in a different host/database than the original document
> 3.
> There is no revision
>
> Is there any built-in couchdb support for this?
>
> Thanks,
> Daniel
>
>
> Link to original SO question: http://stackoverflow.com/q/20386913/647991
>
>

Re: What would be the best way to exactly duplicate a document, with attachments?

Posted by Garren Smith <ga...@apache.org>.
Hi Daniel,

You can use the copy API, that should duplicate the document for you. See the docs for more http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid

Cheers
Garren
On 05 December 2013 at 8:07:04 AM, Daniel Gonzalez (gonvaled@gonvaled.com) wrote:

Hi all,  

Let's say I have host1/db1/doc_id1 which I want to duplicate to  
host2/db2/doc_id2.  

The original document has (maybe) attachments. Currently what I am doing is:  

1.  
Get doc1. I get an attachment stub.  
2.  
Put this document to host2/db2/doc_id2  
3.  
Now I should loop through all attachments, get them, and put them to the  
new document. Probably something will not be guesses right (content_type,  
...).  

Instead, I would like to use a method which:  

1.  
Duplicates the document by using a single GET to obtain the original  
documents + attachments, and creates the new document with a single  
PUT/POST (is this possible, no matter the amount of attachments?)  
2.  
Does not use the filesystem to save the attachments  
3.  
Does not use replication  
4.  
Does not recreate the attachments: specifically, no re-guessing of the  
content type and other attachment properties.  
To make it clear: I want an exact copy of the original document, except  
that:  

1.  
The doc_id is different  
2.  
It is in a different host/database than the original document  
3.  
There is no revision  

Is there any built-in couchdb support for this?  

Thanks,  
Daniel  


Link to original SO question: http://stackoverflow.com/q/20386913/647991