定义
参数
$options: array指定所需选项的数组。
名称类型说明comment
混合
maxTimeMS
整型
The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.
会话
与操作相关联的客户端会话。
1.3版本新增。
Return Values
一个可遍历的MongoDB\Model\IndexInfoIterator ,其中包含collection的每个索引的MongoDB\Model\IndexInfo对象。
错误/异常
MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。
MongoDB\ 驱动程序\Exception\RuntimeException 用于扩展级别的其他错误(例如连接错误)。
例子
以下示例列出了test数据库中restaurantscollection的所有索引:
$collection = (new MongoDB\Client)->test->restaurants; foreach ($collection->listIndexes() as $index) { var_dump($index); }
而输出将类似如下所示:
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" }
另请参阅
listIndexes command reference in the MongoDB manual
Index documentation in the MongoDB manual
枚举集合规范