==================================== MongoDB\\Client::listDatabaseNames() ==================================== .. versionadded:: 1.7 .. default-domain:: mongodb .. contents:: On this page :local: :backlinks: none :depth: 1 :class: singlecol Definition ---------- .. phpmethod:: MongoDB\\Client::listDatabaseNames() Returns names for all databases on the server. .. code-block:: php function listDatabaseNames(array $options = []): Iterator This method has the following parameters: .. include:: /includes/apiargs/MongoDBClient-method-listDatabases-param.rst The ``$options`` parameter supports the following options: .. include:: /includes/apiargs/MongoDBClient-method-listDatabases-option.rst Return Values ------------- An :php:`Iterator `, which provides the name of each database on the server. Errors/Exceptions ----------------- .. include:: /includes/extracts/error-unexpectedvalueexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst Example ------- The following example lists all databases on the server: .. code-block:: php listDatabaseNames() as $databaseName) { var_dump($databaseName); } The output would then resemble:: string(5) "local" string(4) "test" See Also -------- - :phpmethod:`MongoDB\\Client::listDatabases()` - :manual:`listDatabases ` command reference in the MongoDB manual - `Enumerating Databases `_ specification