> On 27. Sep 2018, at 22:11, Bill Stephenson <b...@cherrypc.com.INVALID> wrote:
> 
> I may have missed something but can’t you just load the data from the old 
> doc, and the additional data, and any changes into a new doc and save that, 
> and delete the old on if necessary?


I assume downloading and uploading the attachments is prohibitive.

If that’s the case, and the atomicity issues that Joan outlined are not a 
problem, I’d recommend a doc-by-doc COPY and subsequent read/write of just the 
JSON to add your fields.

Best,
Jan
—

> 
> I may be wrong, but I assume by design you can’t change the _id of an 
> existing doc and “save” it. 
> 
> Kindest Regards,
> 
> Bill 
> 
> 
> 
>> On Sep 27, 2018, at 1:34 PM, Arcadius Ahouansou <arcad...@menelic.com> wrote:
>> 
>> 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
>>   }
>> }
>> }
> 

-- 
Professional Support for Apache CouchDB:
https://neighbourhood.ie/couchdb-support/

Reply via email to