Export From a CouchDB database and import in the CouchDB

User can export a couchdb database and then import it to some remote couchdb database by using the following steps:

1. First Run the following command in the terminal

curl -X GET http://127.0.0.1:5984/[mydatabase]/_all_docs\?include_docs\=true > /Users/[username]/Desktop/db.json

2. Then Remove the total rows line and replace it with { “docs”:[ so that the db.json file will look like the following

{
"docs": [
{"_id": "0", "integer": 0, "string": "0"},
{"_id": "1", "integer": 1, "string": "1"},
{"_id": "2", "integer": 2, "string": "2"}
]
}

3. Run the following command in the terminal

curl -d @db.json -H "Content-type: application/json" -X POST http://127.0.0.1:5984/[mydatabase]/_bulk_docs

Here you have to first change directory to the folder where db.json file is placed and also the database where we want to import the
records must first be created in the couchdb.

One thought on “Export From a CouchDB database and import in the CouchDB

  1. Great! Thank you. I was using sub-standard scripts/utilities imagining such a dark black box to do such a simple but important thing: import without borking on failures and no duplicates, but DOES import missing docs! idempotent in this way = excellent.

Leave a comment