Transferring from MongoDB to CouchDB

So I wanted to move a larger number of records from MongoDB to CouchDB. Here are the basic steps I took:

  1. I  just wanted a selected number of fields (name, address, longitude, latitude) so I used mongoexport to put it into a JSON Array:
    ./mongoexport -d cookography -c places -f name,address,longitude,latitude -o test.json –jsonArray
  2. Both CouchDB & MongoDB use _ID and MongoExport insists on adding it. However it does it in a way the CouchDB hates so I munge it:
    sed ‘s/_id/id/g’ test.json > tested.json
  3. Now you have to format your JSON Array so you can feed it the the REST interface of CouchDB. First add this to the beginning:
    (echo ‘{“docs”:’; cat tested.json) > output.json
    And then this to the end:
    echo “}” >> output.json
  4. Now send this to REST API for CouchDB:DB=”http://127.0.0.1:5984/places”

    curl -d @output.json -X POST $DB/_bulk_docs  -H “Content-Type: application/json”


Posted

in

by

Tags: