Skip to content

Instantly share code, notes, and snippets.

@dommmel
Created December 16, 2011 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dommmel/1485456 to your computer and use it in GitHub Desktop.
Save dommmel/1485456 to your computer and use it in GitHub Desktop.
import json files into mongo/couch
#!/bin/bash
COUCH_DB="http://127.0.0.1:5984/what_ever"
JSON_FOLDER="./jsonFiles/*"
TMP_FILE="/tmp/_couchdb_import.json"
for file in $JSON_FOLDER
do
echo '{"docs":' > $TMP_FILE
cat $file >> $TMP_FILE
echo "}" >> $TMP_FILE
curl -H "Content-type: application/json" -d @$TMP_FILE -X POST $COUCH_DB/_bulk_docs && rm $TMP_FILE
done
#!/bin/bash
JSON_FOLDER="./jsonFiles/*"
DB="test"
COLLECTION="coll"
for file in $JSON_FOLDER
do
mongoimport -d $DB -c $COLLECTION $file --jsonArray
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment