Skip to content

Instantly share code, notes, and snippets.

@iwa
Last active May 7, 2020 13:19
Show Gist options
  • Save iwa/59ccd9535ee5945700c3488a9dfd0298 to your computer and use it in GitHub Desktop.
Save iwa/59ccd9535ee5945700c3488a9dfd0298 to your computer and use it in GitHub Desktop.
Mongoexport all collections to json (updated)
#!/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
@iwa
Copy link
Author

iwa commented May 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment