在ouchDB中更新设计文档时出现文档冲突错误 [英] Document conflict error when updating a design document in couchDB
问题描述
我正在从沙发DB上的 mytest数据库中获取设计文档,但是我想将同一设计文档上载到另一个db,比如说 food。
I am fetching a design document from "mytest" database on couch DB, but i want to upload the same design document on a different db, lets say "food".
我用来获取设计文档的命令是:
Command which i am using to fetch the design document is :
curl http://localhost:5984/mytest/_design/unique > unique.json
我得到的文档看起来像:
and i get a document which looks like:
{"_id":"_design/unique","_rev":"5-e91630ccf1de8b5784333ea24ce50087","views":{"handle":{"map":"function(doc) {emit(doc.user.id, 1);}","reduce":"function(key, values) {return sum(values);}"},"coordinates":{"map":"function(doc) {\nif((doc.coordinates.coordinates[0] < 145.81) && (doc.coordinates.coordinates[0] > 144.28)\n\t&& (doc.coordinates.coordinates[1] < (-37.47)) && (doc.coordinates.coordinates[1] > (-38.44)))\nemit(doc, 1);\n\n}"}},"language":"javascript"}
但是当我上传食物数据库上使用以下相同设计文件:
but when i am uploading the same design file on food database using :
curl -X PUT http://localhost:5984/food/_design/unique -d @unique.json
我得到{错误:冲突,原因:文档更新冲突。}错误。您能帮我解决这个错误吗?我无法理解他的修订号的概念以及我们如何将该文件实际放入数据库中。
I get {"error":"conflict","reason":"Document update conflict."} error. Could you please help me to resolve this error? I am not able to understand he concept of revision numbers and how we can actually put this file onto the database.
谢谢!
推荐答案
更新文档时,必须提供要更新的文档的修订版。它仅允许更新文档的最新版本,并且如果自您上次看到(获取)文档以来有人更新了文档,该文档将失败。对于您的情况,您应该首先对要更新的 food
数据库设计文档执行HEAD http请求。 HEAD非常轻巧,将返回有关文档的基本信息,包括其当前版本(响应中的ETag字段)。然后使用该修订版以新内容更新文档。有关API的更多信息: https://docs.couchdb.org/ zh_CN / stable / api / document / common.html
When you are updating a document, you have to provide the the revision of the document you are updating. It allows to only update the latest version of the document and will fail if someone updated the document since you last saw (fetched) it. In your case you should first execute a HEAD http request to the food
database design doc you are trying to update. HEAD is fairly lightweight and will return basic info about a document, including its current revision (ETag field in the response). Then use that revision to update the doc with new content. More info about the API: https://docs.couchdb.org/en/stable/api/document/common.html
这篇关于在ouchDB中更新设计文档时出现文档冲突错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!