Skip to content

Instantly share code, notes, and snippets.

@pauldotknopf
Created May 5, 2021 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauldotknopf/7bc8909bd7984c34d5457293d4972a6c to your computer and use it in GitHub Desktop.
Save pauldotknopf/7bc8909bd7984c34d5457293d4972a6c to your computer and use it in GitHub Desktop.
Export all collections from a mongo db
#!/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