- Reference >
- Database Commands >
- Diagnostic Commands >
- listDatabases
listDatabases¶
On this page
Definition¶
-
listDatabases¶ The
listDatabasescommand provides a list of all existing databases along with basic statistics about them. ThelistDatabasesmust run against theadmindatabase, as in the following example:The value (e.g.
1) does not affect the output of the command.The
listDatabasescommand can take the following optional field:Field Type Description nameOnlyboolean 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.listDatabasesreturns 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:
The following is an example of a listDatabases result:
listDatabases returns a document that contains:
- A field named
databaseswhose value is an array of documents, one document for each database. Each document contains:- A
namefield with the database name - A
sizeOnDiskfield with the total size of the database file on disk in bytes, and - An
emptyfield specifying whether the database has any data. - For sharded clusters, a
shardsfield that specifies the shards and the size in bytes of the database on disk for each shard.
- A
- A field named
totalSizewhose value is the sum of all thesizeOnDiskfields in bytes. - A field named
okwhose value determines the success of thelistDatabasescommands.1indicates success.
List Database Names Only¶
New in version 3.2.13.
Run listDatabases against the admin database. Specify
the nameOnly: true option:
The following is an example of a listDatabases results
when run with the nameOnly: true option:
See also