Docs Menu
Docs Home
MongoDB Manual
/ / /


On this page

  • Description
  • Examples

Returns a list of available databases. Mongo.getDBNames() calls the listDatabases command.

The Mongo.getDBNames() method doesn't take any parameters.

List the available databases for the current MongoDB instance:


The db.getMongo() method creates a connection to the instance. Mongo.getDBNames() returns:

[ 'admin', 'config', 'local', 'test' ]

Use Mongo.getDBNames() to get a list of collections:

name => db.getSiblingDB( name ).getCollectionNames()

Example output:

[ 'system.users', 'system.keys', 'system.version' ],
  • Mongo.getDBNames() returns a list of databases.

  • map defines a function that iterates over the list of databases. Each iteration of map:

← Mongo.getDB()