Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OlivierJM/7713fd00828bf2d26e0b4eae9364d82f to your computer and use it in GitHub Desktop.
Save OlivierJM/7713fd00828bf2d26e0b4eae9364d82f to your computer and use it in GitHub Desktop.
Export all MongoDB collections to JSON
#!/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