Your question is not really clear about the specific problem. So here just some general guidance on updating documents.
- When designing the database make sure you set the ID rather than allowing couchdb to edit it. This way you can access the document directly when updating it.
- When updating, you are required to prove that you are updating the most recent version of the document. I usually retrieve the document first and make sure you have the most recent '_rev' in the document you'll insert.
- finally the update may fail if a different process has edited the document in the time between retrieving and updating it. So you should capture a failure in the insert and repeat the process until you succeed.
That being said, there are two ways you can store an image:
- As an attachment: I believe nano support the
attachment.insert()
andattachment.get()
functions to do so. As a reference: I would usually rather store the images elsewhere and just store the url or filepath to access them. I've not used nano much but believe you can do this by doing the below.
doc = db.get(docname); // get the document with all existing elements doc['mynewimage'] = myimageurl; // update the document with the new image // this assumes it's a dictionary db.insert(doc); // inserts the document with the correct _id (= docname) // and _rev