Skip to content

Instantly share code, notes, and snippets.

@serpent403
Last active January 2, 2016 00:49
Show Gist options
  • Save serpent403/8226455 to your computer and use it in GitHub Desktop.
Save serpent403/8226455 to your computer and use it in GitHub Desktop.
Exports all the collections from a given database.
#!/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