- Reference >
- MongoDB\Database Class >
- MongoDB\Database::listCollectionNames()
MongoDB\Database::listCollectionNames()
New in version 1.7.
On this page
Definition
-
MongoDB\Database::listCollectionNames Returns names for all collections in this database.
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 authorizedCollectionsboolean Optional. A flag that determines which collections are returned based on the user privileges when access control is enabled. For more information, see the listCollections command documentation.
For servers < 4.0, this option is ignored.
New in version 1.12.
filterarray|object Optional. A query expression to filter the list of collections.
You can specify a query expression for collection fields (e.g.
name,options).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 collection in the database.
Example
The following example lists all of the collections in the test database:
The output would then resemble:
string(11) "restaurants"
string(5) "users"
string(6) "restos"
The following example lists all collections whose name starts with "rest"
in the test database:
The output would then resemble:
string(11) "restaurants"
string(6) "restos"
Note
When enumerating collection names, a filter expression can only filter based on a collection’s name and type. No other fields are available.
See Also
MongoDB\Database::listCollections()- listCollections command reference in the MongoDB manual
- Enumerating Collections specification