- Reference >
- MongoDB\Database Class >
- MongoDB\Database::listCollections()
MongoDB\Database::listCollections()
On this page
Definition
-
MongoDB\Database::listCollections
Returns information for all collections in this database.
This method has the following parameters:
Parameter Type Description $options
array Optional. An array specifying the desired options. The
$options
parameter supports the following options:Option Type Description authorizedCollections
boolean 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.
comment
mixed Optional. Enables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs.
This is not supported for server versions prior to 4.4 and will result in an exception at execution time if used.
New in version 1.13.
filter
array|object Optional. A query expression to filter the list of collections.
You can specify a query expression for collection fields (e.g.
name
,options
).maxTimeMS
integer Optional. The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point. session
MongoDB\Driver\Session Optional. Client session to associate with the operation.
New in version 1.3.
Return Values
A traversable MongoDB\Model\CollectionInfoIterator
, which contains
a MongoDB\Model\CollectionInfo
object for each collection in the
database.
Example
The following example lists all of the collections in the test
database:
The output would then resemble:
The following example lists all collections whose name starts with "rest"
in the test
database:
The output would then resemble:
See Also
MongoDB\Database::listCollectionNames()
- listCollections command reference in the MongoDB manual
- Enumerating Collections specification