Last active
May 7, 2020 13:19
-
-
Save iwa/59ccd9535ee5945700c3488a9dfd0298 to your computer and use it in GitHub Desktop.
Mongoexport all collections to json (updated)
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=$1 | |
COLLECTIONS=$(mongo localhost:27017/$DB --quiet --eval "db.getCollectionNames()" | grep \" | tr -d '\[\]\"[:space:]' | tr ',' ' ') | |
for collection in $COLLECTIONS; do | |
echo "Exporting $DB/$collection ..." | |
mongoexport --db=$DB -c=$collection -o=$collection.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
original script here