You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Matteo Guadrini <ma...@hotmail.it> on 2021/10/13 15:30:35 UTC

R: How to clone a document with attachments?

I use my powershell module for this operation with Copy-CouchDBDocuments...https://pscouchdb.readthedocs.io/en/latest/documents.html#copy-a-document
Documents — PSCouchDB documentation<https://pscouchdb.readthedocs.io/en/latest/documents.html#copy-a-document>
Sort¶. The sort field contains a list of field name and direction pairs, expressed as a basic array. The first field name and direction pair is the topmost level of sort.
pscouchdb.readthedocs.io


Matteo Guadrini

________________________________
Da: Nick Vatamaniuc <va...@gmail.com>
Inviato: giovedì 30 settembre 2021 18:24
A: user@couchdb.apache.org <us...@couchdb.apache.org>
Oggetto: Re: How to clone a document with attachments?

Without an example it's hard to tell why it doesn't work. The initial
guess is it's because you might have fetched attachments as stubs and
not their full body.

For example by default fetching a doc we might get:

   "_attachments": {
        "att1": {
            "content_type": "application/json",
            "digest": "md5-Ghxmlil8kHHM0/6YedoKwQ==",
            "length": 10,
            "revpos": 3,
            "stub": true
        }
    }


Notice how that doesn't contain any attachment data. But if you use
attachments=true you do get them

  "_attachments": {
    "att1": {
      "content_type": "application/json",
      "revpos": 3,
      "digest": "md5-Ghxmlil8kHHM0/6YedoKwQ==",
      "data": "eyJjIjogImQifQ=="
    }
  }

So make sure to use the second form if you intend to clone the
document with all of its attachments

Cheers,
-Nick

On Wed, Sep 29, 2021 at 3:09 PM Erik Verheul <te...@verheulconsultants.nl> wrote:
>
> Hi all,
>
> I tried do clone multiple documents, some with attachments,  by creating a new _id and a copy of the fields from the original including "_attachments".
> The _bulk_docs post request to save the cloned documents failed with status code 412. If no document has an attachment all is fine.
>
> How can I avoid this error?
>
> Any help would be very much appreciated.
> Thanks,
> Erik
>
>