I need to get a document, change/insert/delete some fields and put it back.
The "put" action requires the current revision of the document, but in nano I cannot find any function which takes a revision as a parameter and inserts the document back into the database.
How can I do this with nano?
Note: This is the general algorithm, it is not specific to any library since nano's insert()
method doesn't offer anything automated for updating documents.
Get the document, save the current revision, apply your changes and try to send the document with the saved revision number.
Make sure to handle possible 409 conflict responses which occur when a document was altered meanwhile.
In that case you should refetch the document, save the revision number, reapply your changes and then try to send it again with the new revision.
So here is the algorithm:
Checkout the CouchDB HTTP Document API's PUT section and CouchDB's Replication and Conflicts wiki page for more information on that matter. You may also find How To Update A Document With Nano (The CouchDB Client for Node.js) helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With