- Reference >
- MongoDB\Client Class >
- MongoDB\Client::listDatabaseNames()
MongoDB\Client::listDatabaseNames()
New in version 1.7.
On this page
Definition
-
MongoDB\Client::listDatabaseNames Returns names for all databases on the server.
This method has the following parameters:
Parameter Type Description $optionsarray Optional. An array specifying the desired options. The
$optionsparameter supports the following options:Option Type Description authorizedDatabasesboolean Optional. A flag that determines which databases are returned based on the user privileges when access control is enabled. For more information, see the listDatabases command documentation.
For servers < 4.0.5, this option is ignored.
New in version 1.7.
filterarray|object Optional. A query expression to filter the list of databases.
You can specify a query expression for database fields (e.g.
name,sizeOnDisk,empty).New in version 1.3.
maxTimeMSinteger Optional. The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point. sessionMongoDB\Driver\Session Optional. Client session to associate with the operation.
Sessions are not supported for server versions prior to 3.6.
New in version 1.3.
Return Values
An Iterator, which provides the name of each database on the server.
Errors/Exceptions
MongoDB\Exception\UnexpectedValueException if the command
response from the server was malformed.
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
MongoDB\Driver\Exception\RuntimeException for other errors at the driver level (e.g. connection errors).
Example
The following example lists all databases on the server:
The output would then resemble:
string(5) "local"
string(4) "test"
See Also
MongoDB\Client::listDatabases()- listDatabases command reference in the MongoDB manual
- Enumerating Databases specification