Navigation
This version of the documentation is archived and no longer supported.

listDatabases

On this page

Definition

listDatabases

The listDatabases command provides a list of all existing databases along with basic statistics about them. The listDatabases must run against the admin database, as in the following example:

db.adminCommand( { listDatabases: 1 } )

The value (e.g. 1) does not affect the output of the command.

The listDatabases command can take the following optional field:

Field Type Description
nameOnly boolean

Optional. A flag to indicate whether the command should return just the database names (which does not require database locks) or return the database names and size information (which does require database locks).

Default is false; i.e. listDatabases returns the name and size information of the databases.

New in version 3.2.13.

Examples

List Database Names and Sizes

Run listDatabases against the admin database:

db.adminCommand( { listDatabases: 1 } )

The following is an example of a listDatabases result:

{
   "databases" : [
      {
         "name" : "admin",
         "sizeOnDisk" : 83886080,
         "empty" : false
      },
      {
         "name" : "local",
         "sizeOnDisk" : 83886080,
         "empty" : false
      },
      {
         "name" : "test",
         "sizeOnDisk" : 83886080,
         "empty" : false
      }
   ],
   "totalSize" : 251658240,
   "ok" : 1
}

listDatabases returns a document that contains:

  • A field named databases whose value is an array of documents, one document for each database. Each document contains:
    • A name field with the database name
    • A sizeOnDisk field with the total size of the database file on disk in bytes, and
    • An empty field specifying whether the database has any data.
    • For sharded clusters, a shards field that specifies the shards and the size in bytes of the database on disk for each shard.
  • A field named totalSize whose value is the sum of all the sizeOnDisk fields in bytes.
  • A field named ok whose value determines the success of the listDatabases commands. 1 indicates success.

List Database Names Only

New in version 3.2.13.

Run listDatabases against the admin database. Specify the nameOnly: true option:

db.adminCommand( { listDatabases: 1, nameOnly: true} )

The following is an example of a listDatabases results when run with the nameOnly: true option:

{
   "databases" : [
      {
         "name" : "admin"
      },
      {
         "name" : "local"
      },
      {
         "name" : "test"
      }
   ],
   "ok" : 1
}
←   listCommands netstat  →