Skip to content

Instantly share code, notes, and snippets.

@denzhel
Last active January 26, 2021 21:32
Show Gist options
  • Save denzhel/ff3ae4fa8cde39bd945cfcf76da62a5b to your computer and use it in GitHub Desktop.
Save denzhel/ff3ae4fa8cde39bd945cfcf76da62a5b to your computer and use it in GitHub Desktop.
Export all collections from a database

If you want to export specific collections from a specific database, you can use this bash loop:

for collection in \ 
$(mongo <databaseName> --quiet --eval "rs.slaveOk(); db.getCollectionNames().join('\n')" | grep <collectionPrefix) ; \
do mongoexport --collection=$collection --db=<databaseName> --out=$collection ; \
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment