Updating a CouchDB document in nano [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-05 08:09:57

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:

  1. Get document
  2. Save the _rev
  3. Apply changes
  4. Try to send updated document with saved _rev
  5. Go to step 1 in case of a 409

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!