CouchDB: how to use _revs_diff to get document revision ID

半腔热情 提交于 2019-12-23 10:15:54

问题


I tried to test couchDB's _revs_diff api to get document revisions. Here is the command I used

curl -X POST http://******:******@localhost:5984/grocery-sync/_revs_diff -H "Content-type:application/json" 

the result is

{"error":"unknown_error","reason":"badarg"}

Does anyone know the reason for that?


回答1:


According to the CouchDB wiki page, _revs_diff will return a value if the revisions for a given document are invalid. No examples using curl are given.

Looking at this mailing list posting the problem appears to be that you need to include document and revision information, like this:

$ curl -X POST -H "Content-type:application/json" \
   http://*:*@localhost:5984/grocery-sync/_revs_diff \
   -d '{"0d63eac0ca9a37daa062b23853a4cf4d":["1-e9e4e9c76323a267ff4f780f9f979b9f", "12-3286453e55eb2c401bc194670075f942"]}'

Where the dictionary key (0d63...cf4d) is the document id and the array are revision ids. In this example both revisions (1-... and 12-...) are present in the database so the response is

{}

If I provide a missing revision id (one I invented):

$ curl -X POST -H "Content-type:application/json"  \
  http://*:*@localhost:5984/grocery-sync/_revs_diff \
  -d '{"0d63eac0ca9a37daa062b23853a4cf4d":["1-abcdef"]}'

The response is

{"0d63eac0ca9a37daa062b23853a4cf4d":{"missing":["1-abcdef"]}}


来源:https://stackoverflow.com/questions/13179091/couchdb-how-to-use-revs-diff-to-get-document-revision-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!