- Reference >
- MongoDB\Collection Class >
- MongoDB\Collection::listIndexes()
MongoDB\Collection::listIndexes()
On this page
Definition
-
MongoDB\Collection::listIndexes
Returns information for all indexes for this collection.
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 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.
Return Values
A traversable MongoDB\Model\IndexInfoIterator
, which contains a
MongoDB\Model\IndexInfo
object for each index for the collection.
Errors/Exceptions
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 of the indexes for the restaurants
collection in the test
database:
The output would then resemble:
object(MongoDB\Model\IndexInfo)#8 (4) {
["v"]=>
int(1)
["key"]=>
array(1) {
["_id"]=>
int(1)
}
["name"]=>
string(4) "_id_"
["ns"]=>
string(16) "test.restaurants"
}
object(MongoDB\Model\IndexInfo)#12 (4) {
["v"]=>
int(1)
["key"]=>
array(1) {
["cuisine"]=>
float(-1)
}
["name"]=>
string(10) "cuisine_-1"
["ns"]=>
string(16) "test.restaurants"
}
object(MongoDB\Model\IndexInfo)#8 (4) {
["v"]=>
int(1)
["key"]=>
array(1) {
["borough"]=>
float(1)
}
["name"]=>
string(9) "borough_1"
["ns"]=>
string(16) "test.restaurants"
}
See Also
- Indexes
- listIndexes command reference in the MongoDB manual
- Index documentation in the MongoDB manual
- Enumerating Collections specification