MongoDB\Client::listDatabaseNames()
New in version 1.7.
Definition
Parameters
$options
: arrayAn array specifying the desired options.
NameTypeDescriptionauthorizedDatabases
boolean
A flag that determines which databases are returned based on the user privileges when access control is enabled. To learn more, see the listDatabases command reference in the MongoDB Server manual.
New in version 1.7.
comment
mixed
Enables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs.
To use this option, you must connect to MongoDB 6.0 or later. If you are connected to an earlier version, the server returns an exception at execution time.
New in version 1.13.
filter
array|object
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.
maxTimeMS
integer
The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.
session
Client session to associate with the operation.
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 extension level (e.g. connection errors).
Example
The following example lists all databases on the server:
$client = new MongoDB\Client; foreach ($client->listDatabaseNames() as $databaseName) { var_dump($databaseName); }
The output would then resemble:
string(5) "local" string(4) "test"
See Also
listDatabases command reference in the MongoDB manual
Enumerating Databases specification