Hello.
I have a set of documents with _id in the format "doc-1", ..., "doc-N"
shown below.
I need to change the _id of those documents from let's say "doc-1" to
"user-1" and also add some additional fields to the documents.

To prove my strategy, I started by loading only 1 document, then updating
the _id, add additional fields, remove the _rev field and save it.
This fails with error:

HTTP 412 Precondition Failed

{"error":"missing_stub","reason":"Invalid attachment stub in user-1 for
photo.png"}

when I remove the stub:true, I get

{"error":"bad_request","reason":"Invalid attachment data for photo.png"}


Is there a way to link this new document to the existing attachment without
having to fully load and copy the attachment?

I have noticed that there is also a COPY API available for CouchDB which is
able to copy a document preserving all attachments.
My only issue with the COPY is that it seems to operate only on a single
document and there seem to be no way of modifying the document being
copied.
In my case, I need to be able to perform copy and multiple documents at
once.

Any hint will be very appreciated.

Thank you very much.

Arcadius.


{
  "_id": "doc-001",
  "_rev": "3-61954f961abfb012ff7262ebb2d40426",
  "_attachments": {
    "photo.png": {
      "content_type": "image/png",
      "revpos": 3,
      "digest": "md5-IfggOdAm507L7pnXzfCzWA==",
      "length": 6873,
      "stub": true
    }
  }
}

Reply via email to