Last active
November 16, 2020 01:01
-
-
Save unicornist/c10cb86c6113aba7fb31c1e092c18552 to your computer and use it in GitHub Desktop.
Get all MongoDB database names and collections names for each, using mongo binary and jq
This file contains hidden or 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
dbs=$( | |
mongo --quiet --eval "db.adminCommand('listDatabases')" | | |
jq ".databases[].name|select((.!=\"admin\") and (.!=\"config\") and (.!=\"local\"))" | | |
sed "s/\"//g" | |
) | |
for db in $dbs | |
do | |
collections=$( | |
mongo $db --quiet --eval 'db.getCollectionNames()' | | |
jq .[] | | |
sed "s/\"//g" | |
) | |
for collection in $collections | |
do | |
echo $db - $collection | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment