Created
May 5, 2021 15:02
-
-
Save pauldotknopf/7bc8909bd7984c34d5457293d4972a6c to your computer and use it in GitHub Desktop.
Export all collections from a mongo db
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()" | tr -d '\[\]\"[:space:]' | tr ',' ' ') | |
for collection in $COLLECTIONS; do | |
echo "Exporting $DB/$collection ..." | |
mongoexport -d $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