top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Mongo: Get list of databases with a UNIX command

+3 votes
396 views

I would like to get the list of the database manage by on server through a single shell command, on UNIX. The objective is to be able to do a full export of all dbs for validation purposes.
Right now, I can see only two ways to do this.
- Start mongo, type show dbs, to a manual copy of the list and exit. I do not like this way as this requires several manual operations.
- Scan the files.*.0 in the db directory.
This works but is dependent on the format of the database.Is there any better way to list all the DBs managed by a server through a single command? I am using MongoDB 3.0.4 on Scientific Linux.

posted Aug 29, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Yes,
Step 1: Save this script in file ShowAllDBNames.js where mongodb exe is,

db.adminCommand('listDatabases').databases.
     filter(function(it)
    {return it.name != "local";
    }).
     forEach(function(it){print(it.name);
 })

Step 2:
then write this command and execute:

mongo --quiet ShowAllDBNames.js
answer Feb 9, 2016 by Shivam Kumar Pandey
Similar Questions
+2 votes

I have a huge code base and it is showing files with zero bytes .
Can someone share a linux command to delete files with zero bytes in one attempt ?

0 votes

MongoException on Mongo Insert (errorCode=72): Command failed with error 72: 'Writes to config servers must have batch size of 1, found 1000'
I have this error on a collection bulk insert via mongos. Can you help?

0 votes

Write a unix command to display the every character in the word "QUERYHOME" in new line.

Ex : Input - QUERYHOME
output: Q
U
E
R
Y
H
O
M
E

...