Reputation: 303
My MongoDB has more than 100 databases in it.
Whenever i use show dbs command my screen is filled with all databases names and it makes hard to find a particular database.
How to display only those databases which contain a particular substring as we can query in MySQL for displaying particular databases with ( show databases like '%SUBSTR%' ) query.
Upvotes: 0
Views: 1296
Reputation: 16551
Another option is:
> db.getMongo().getDBNames().forEach(
function(databaseName) {
if (databaseName.match(/SUBSTR/i))
print(databaseName);
}
);
> var showdbs = function(pattern) {
db.getMongo().getDBNames().forEach(
function(databaseName) {
if (databaseName.match(new RegExp(pattern, 'i')))
print(databaseName);
});
};
> showdbs('SUBSTR'); // ALL: showdbs();
Upvotes: 1
Reputation: 3129
If you are on a *nix OS you could run the following command.
mongo --eval "db.adminCommand('listDatabases')['databases']" | grep "SUBSTR"
Note: You need to be admin to run this command.
Upvotes: 0
Reputation: 685
We do not have options like that. But your problem can be resolved by outputting the result into a txt file and later opening it
$ mongo | tee outnew.txt
In the mongo shell you can the give the show dbs command and exit.
mongo> show dbs;
mongo> exit
Then using gedit or excel access the outnew.txt file. Hope it helped.
Upvotes: 2