Green Acorn


Export & Import a Database with CouchDB

A simple way of exporting a CouchDB database to a file, is by running the following Curl command in the terminal window:

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

Next step is to modify the exported json file to look like something like the below (note the _id):

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

Main bit you need to look at is adding the documents in the “docs” code block. Once this is done you can run the following Curl command to import the data to a CouchDB database:

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

Duplicating a database

If you want to duplicate a database from one server to another. Run the following command:

curl -H 'Content-Type: application/json' -X POST http://localhost:5984/_replicate -d ' {"source": "", "target": "http://localhost@:5984/dbname/"}'


Posted in: CouchDB

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>