错误:文档更新冲突

时间:2014-02-14 03:51:07

标签: json macos unix terminal couchdb

当我尝试从我的数据库中获取数据时,我收到以下错误:

{"error":"conflict","reason":"Document update conflict."}

这是我的完整终端。

Last login: Thu Feb 13 22:45:22 on ttys000
Idriss-iMac:~ idrisk$ cd Spika-Server
Idriss-iMac:Spika-Server idrisk$ cd install
Idriss-iMac:install idrisk$ curl -X POST http://127.0.0.1:5984/spikademo -  d@designdocuments.dump -H "Content-Type: application/json"
{"error":"conflict","reason":"Document update conflict."}
Idriss-iMac:install idrisk$ 

我的数据库是在我在浏览器中输入http://127.0.0.1:5984/spikademo时创建的,我得到以下内容:

{"db_name":"spikademo","doc_count":2,"doc_del_count":0,"update_seq":2,"purge_seq":0,"compact_running":false,"disk_size":8290,"data_size":2116,"instance_start_time":"1392349603181164","disk_format_version":6,"committed_update_seq":2}

2 个答案:

答案 0 :(得分:0)

您应该使用curl http://127.0.0.1:5984/spikademo来获取数据库信息。

答案 1 :(得分:0)

我在尝试更新文档时遇到了同样的错误:

$ curl -X PUT http://admin:****@192.168.1.106:5984/sample/doc7 -d @doc7
{"error":"conflict","reason":"Document update conflict."}

我的doc7文件看起来像这样:

{
    "name": "David J.",
    "title": "Sir",
}

要解决此错误,我首先发出GET请求以获取该文档的修订号:

$ curl -X GET http://admin:****@192.168.1.106:5984/sample/doc7
{"_id":"doc7","_rev":"2-c703b339b3d4d207d07a082e736ee021","name":"David","title":"Dr"}

然后我将"_rev":"2-c703b339b3d4d207d07a082e736ee021"添加到我的doc7文件中,如下所示:

{
    "name": "David J.",
    "title": "Sir",
    "_rev":"2-c703b339b3d4d207d07a082e736ee021"
}

现在,我可以毫无错误地更新我的文档:

$ curl -X PUT http://admin:backpage\ ct@192.168.1.106:5984/sample/doc7 -d @doc7
{"ok":true,"id":"doc7","rev":"3-becda8d4cb81e588ae7125e6a0a372d2"}

请注意,更新后,CouchDB会返回文档的新版本rev

根据this answer,您似乎可以发送HEAD请求以获取文档的修订号。当我执行HEAD请求时,我需要使用curl的-I选项,ETag返回修订号,如下所示:

$ curl -X HEAD http://admin:**@192.168.1.106:5984/sample/doc7  -I
HTTP/1.1 200 OK
X-CouchDB-Body-Time: 0
X-Couch-Request-ID: 27d4e242fb
Server: CouchDB/2.1.1 (Erlang OTP/18)
ETag: "4-dfd11b5ba753d3b80e522e3b63c0a745"
Date: Tue, 27 Mar 2018 17:11:48 GMT
Content-Type: application/json
Content-Length: 121
Cache-Control: must-revalidate