在nano中更新CouchDB文档 [英] Updating a CouchDB document in nano

查看:111
本文介绍了在nano中更新CouchDB文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取文档,更改/插入/删除一些字段,然后放回原处。

I need to get a document, change/insert/delete some fields and put it back.

放置 操作需要当前文档的修订版本,但是在nano中,我找不到任何将修订版本作为参数并将文档插入数据库的函数。

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.

我该怎么办

推荐答案

注意:这是常规算法,因为 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.

这篇关于在nano中更新CouchDB文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆