Note. This is a general algorithm, it is not specific to any library, since the nano insert()
method does not offer anything automated for updating documents.
Get the document, save the current version, apply the changes and try to send the document with the saved revision number.
Be sure to handle the possible 409 conflict responses that occur when the document has been modified in the meantime.
In this case, you must restore the document, save the version number, reapply your changes, and then try sending it again with the new version.
So here is the algorithm:
- Get a document
- Save _rev
- Apply Changes
- Try sending an updated document with _rev saved
- Go to step 1 in case of 409
Checkout CouchDB HTTP Document API PUT Section and CouchDB Replication and Conflicts for more information on this. You can also find How to update a document using Nano (CouchDB client for Node.js) .
source share