patternMinor
List all MongoDB databases from Linux bash terminal
Viewed 0 times
databasesterminalallmongodblinuxlistfrombash
Problem
Can you list all databases in MongoDB from a linux bash terminal? I cannot find the correct command. I am trying to list all so as that I can write a bash script to backup all DB's individually. Is there a better way?
Solution
"show dbs" calculate the databases sizes and that may take some time.
You can pass this command to the mongo shell, then clean the response:
You can pass this command to the mongo shell, then clean the response:
echo "db.getMongo().getDBNames()"|mongo --quiet |tr -d \[\] | tr , "\n"|cut -c3-| tr -d \"Code Snippets
echo "db.getMongo().getDBNames()"|mongo --quiet |tr -d \[\] | tr , "\n"|cut -c3-| tr -d \"Context
StackExchange Database Administrators Q#188305, answer score: 3
Revisions (0)
No revisions yet.