Last active
January 2, 2016 00:49
-
-
Save serpent403/8225967 to your computer and use it in GitHub Desktop.
Imports all bson files present in a directory into the given database. Name of bson file must match the corresponding collection name. Place this script in the directory where your bson files are present and run it.
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 | |
host=localhost | |
db=mydatabase | |
for bson_file in `ls *.bson` | |
do | |
echo "importing $bson_file" | |
collection=$(echo "${bson_file}" | cut -d'.' -f1) | |
bson_path="$(pwd)/$bson_file" | |
mongoimport --host $host --db $db --collection $collection $bson_path | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment