- 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 filterdocument Optional. A query predicate that determines which databases are listed.
You can specify a condition on any of the database fields returned in its output:
namesizeOnDiskemptyshards
New in version 3.4.2.
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.4.3.
Output¶
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 files on disk in bytes. - An
emptyfield specifying whether the database has any data. - For sharded clusters, a
shardsfield that includes the shard 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.
Examples¶
List Database Names and Sizes¶
Run listDatabases against the admin database:
The following is an example of a listDatabases result:
List Database Names Only¶
New in version 3.4.3.
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:
List Databases That Match the Filter¶
New in version 3.4.2.
Run listDatabases against the admin database. Specify
the filter option to only list databases that match the specified filter criteria.
For example, the following specifies a filter such that
listDatabases only returns information on databases whose
name matches the specified regular expression:
See also