加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

批量更新CouchDB数据库,而不是每个文档的_rev值?

发布时间:2020-12-12 08:38:14 所属栏目:MsSql教程 来源:网络整理
导读:根据 CouchDB Wiki on PUT operations. To update an existing document,you also issue a PUT request. In this case,the JSON body must contain a _rev property ,which lets CouchDB know which revision the edits are based on. If the revision of the
根据 CouchDB Wiki on PUT operations.

To update an existing document,you also issue a PUT request. In this case,the JSON body must contain a _rev property,which lets CouchDB know which revision the edits are based on. If the revision of the document currently stored in the database doesn’t match,then a 409 conflict error is returned.

我的目标是执行bulk_docs更新:

curl -X POST [domain]/[couch db name]/_bulk_docs -H "Content-type: application/json" -d @[some document].json

我的工作流程是这样的:

>我的资料位于Google文件试算表中.
>我将电子数据表数据转换为JSON,复制并粘贴到Mr. Data Converter
>我使用cURL(如上所示)添加/更新文档

问题是,我第一次添加新的文档,一切都很好,但是下次发布相同的文档时,我会收到每个文档的以下错误:

…{“id”:”28″,” error”:”conflict”,”reason”:”Document update conflict.”}…

有没有办法更新现有文档而不包括_rev属性?

解决方法

根据设计,您无法盲目更新CouchDB文档,您只能尝试更新文档的特定修订版本.

对于单个文档,您可以使用CouchDB update handler将其从客户端隐藏,因为更新处理程序将传递包含其修订版本的现有文档(如果存在).

对于文档集合,使用_bulk_docs时,可以添加“new_edits”:false,这将强制插入冲突而不是拒绝(尽管您仍然需要传递_rev,但不一定是当前的) .

所有这一切,最好遵守规则.获取您要更新的文档的当前版本,尝试更新它,如果您获得了409,获取新版本,根据需要进行合并,然后再次更新.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读