MongoDB – List All Databases from Linux Bash Terminal

linuxmongodb-3.0

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?

Best Answer

"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:

echo "db.getMongo().getDBNames()"|mongo --quiet |tr -d \[\] | tr , "\n"|cut -c3-| tr -d \"