Last active
January 2, 2016 00:49
-
-
Save serpent403/8226455 to your computer and use it in GitHub Desktop.
Exports all the collections from a given database.
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 | |
db=mydatabase | |
out_dir="./" | |
tmp_file="fadlfhsdofheinwvw.js" | |
echo "print('_ ' + db.getCollectionNames())" > $tmp_file | |
cols=`mongo $db $tmp_file | grep '_' | awk '{print $2}' | tr ',' ' '` | |
for c in $cols | |
do | |
mongoexport -d $db -c $c -o "$out_dir/${c}.bson" | |
done | |
rm $tmp_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment