OPTIONS

listDatabases

On this page

Definition

listDatabases

The listDatabases command provides a list of all existing databases along with basic statistics about them:

{ listDatabases: 1 }

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

The listDatabases must run against the admin database, as in the following example:

db.adminCommand( { listDatabases: 1 } )

Output

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,
   "totalSizeMb" : 240,
   "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.
  • A field named totalSizeMb whose value is totalSize in megabytes.
  • A field named ok whose value determines the success of the listDatabases commands. 1 indicates success.
←   explain dbHash  →

Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.