So I wanted to move a larger number of records from MongoDB to CouchDB. Here are the basic steps I took:
- 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 - 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 - 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 - 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”