Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB: how to use _revs_diff to get document revision ID

Tags:

couchdb

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?

like image 731
Bai Avatar asked Oct 06 '22 03:10

Bai


1 Answers

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"]}}
like image 115
lambmj Avatar answered Oct 13 '22 00:10

lambmj