Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

couchDB restore error : Missing JSON list of 'docs'

Tags:

json

couchdb

when copying a database from one host to another I get the folowing error : Missing JSON list of 'docs'

Here is what I do :

source> curl -X GET http://127.0.0.1:5984/cozy/_all_docs?include_docs=true > cozy.dump

destination> curl -X PUT http://127.0.0.1:5984/cozy 
{"ok":true}

destination> curl -d @cozy.dump -H "Content-type: application/json" -X POST http://localhost:5984/cozy/_bulk_docs 
{"error":"bad_request","reason":"Missing JSON list of 'docs'"}

any idea ?

Thanks !

like image 535
Patrice Avatar asked Mar 23 '14 08:03

Patrice


2 Answers

This is, indeed, a problem with versions.

Fortunately it is fairly easy to fix: just change the first line in the dump, eg.

{"total_rows": 8244, "offset": 0, "rows": [

to

{"docs": [

The dumps can now be used in the later versions.

like image 193
Niels Abildgaard Avatar answered Oct 04 '22 18:10

Niels Abildgaard


I know this is an old question but I am still posting an answer in case some one else is looking for the solution. The bulk docs api accepts the request in a certain form.

{docs:[{},{},{}]}

The docs key must contain an array of documents to be bulk inserted. What op did with

curl -X GET http://127.0.0.1:5984/cozy/_all_docs?include_docs=true > cozy.dump

was that he simply stored the couchdb response of the format

{
 total_rows: 4,
 offset: 0,
 rows: [....]
}

into the cozy.dump file. As we have seen above this file is not in a form that can be consumed by the bulk docs api. Hence the error

{"error":"bad_request","reason":"Missing JSON list of 'docs'"}

Couchdb needs a JSON list of docs to perform the bulk insert.

Another point to be noted here is that if you supply an _id and _rev parameter couchdb performs a bulk update rather than a bulk insert. If you just want to copy one database to another use http://wiki.apache.org/couchdb/Replication

like image 44
Akshat Jiwan Sharma Avatar answered Oct 04 '22 18:10

Akshat Jiwan Sharma