Forked from thbkrkr/mongoexport-all-collections-as-json.sh
Created
September 19, 2018 11:18
-
-
Save hydeenoble/79e582cf2c0e0ba5b923c5bfb44a7812 to your computer and use it in GitHub Desktop.
Export all MongoDB collections to JSON
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()" | sed 's/,/ /g') | |
for collection in $COLLECTIONS; do | |
echo "Exporting $DB/$collection ..." | |
mongoexport -d newtickettoolDB -c $collection -o $collection.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment