问题描述
根据。
我的目标是执行 bulk_docs更新:
curl -X POST [domain]/[couch db name]/_bulk_docs -H "Content-type: application/json" -d @[some document].json
我的工作流程如下:
- 我的数据在Google文档电子表格中。
- 我通过复制并粘贴到
- 我使用cURL(如上所示)添加/更新文档
- My data is in an Google Docs spreadsheet.
- I convert the spreadsheet data to JSON by copying and pasting into Mr. Data Converter
- I use cURL (as show above) to add/update documents
问题在于,第一次添加新文档时,一切运行正常,但是下次发布相同文档时,每个文档都会出现以下错误:
The problem is that the first time I add new documents, everything works perfectly, however the next time I post the same documents, I get following error for each document:
是否可以在不包含 _rev 属性的情况下更新现有文档?
Is there any way to update an existing document without including a _rev property?
推荐答案
通过设计,您不能盲目更新CouchDB文档,只能尝试更新文档的特定修订版。
By design, you cannot update a CouchDB document blindly, you can only attempt to update a specific revision of a document.
对于单个文档,您可以使用将其隐藏来自客户端的更新处理程序将被传递给现有文档(如果存在),包括其修订版。
For a single document, you can use a CouchDB update handler to hide this from the client as an update handler will be passed the existing document (if it exists) including its revision.
对于文档集合,使用 _bulk_docs
时,可以添加 new_edits:false
这将强制插入冲突而不是拒绝(尽管您仍然需要传递 _rev ,但不必是当前的)。
For a collection of documents, when using _bulk_docs
, you can add "new_edits": false
which will forcibly insert conflicts instead of rejection (though you'll still need to pass a _rev, it just doesn't have to be the current one).
总而言之,最好遵循规则。抓取您要更新的文档的当前版本,尝试进行更新,如果得到409,则获取新版本,视情况进行合并,然后再次更新。
All that said, it would be better to follow the rules. Grab the current revision of the document you would like to update, attempt to update it, if you get a 409, get the new version, merge as appropriate, and update again.
这篇关于批量更新CouchDB数据库而每个文档没有_rev值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!