Created
December 16, 2011 10:07
-
-
Save dommmel/1485456 to your computer and use it in GitHub Desktop.
import json files into mongo/couch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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