Docs Menu

Docs HomeMongoDB 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()Mongo.getDBs() →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.