且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在nano中更新CouchDB文档

更新时间:2021-12-03 21:43:08

注意:这是常规算法,因为 nano的 insert() 方法没有

获取文档,保存当前修订,应用更改并尝试将保存的修订发送给文档

Get the document, save the current revision, apply your changes and try to send the document with the saved revision number.

请确保处理可能同时更改文档时发生的409个冲突。

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.

因此,算法如下:


  1. 获取文档

  2. 保存_rev

  3. 应用更改

  4. 尝试发送带有保存的_rev的更新文档

  5. 如果出现409,请转到步骤1

  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

检出 CouchDB HTTP文档API的PUT部分和CouchDB的复制与冲突 Wiki页面,以获取有关此问题的更多信息。您可能还会发现如何使用Nano(Node.js的CouchDB客户端)更新文档很有帮助。

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.