Docs 菜单

Docs 主页PHP 库手册

MongoDB\Collection::listIndexes()

在此页面上

  • 定义
  • 参数
  • 返回值
  • 错误/异常
  • 例子
  • 另请参阅
MongoDB\Collection::listIndexes()

返回此collection的所有索引的信息。

function listIndexes(array $options = []): MongoDB\Model\IndexInfoIterator
$options : array

指定所需选项的数组。

名称
类型
说明
注释
混合

允许用户指定任意注释,以帮助通过 数据库分析器currentOp输出和日志跟踪操作。

自 MongoDB 4.4 起此选项可用,如果为旧服务器版本指定,则会在执行时导致异常。

1.13 版本中的新增功能

maxTimeMS
整型

对游标进行处理操作的累积时间限制(以毫秒为单位)。 MongoDB 最早会在中断点之后中止操作。

会议

与操作相关联的客户端会话。

1.3 版本中的新增功能

一个可遍历的MongoDB\Model\IndexInfoIterator ,其中包含collection的每个索引的MongoDB\Model\IndexInfo对象。

MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。

MongoDB\Driver\Exception\RuntimeException 驱动程序级别的其他错误(例如连接错误)。

以下示例列出了test数据库中restaurantscollection的所有索引:

<?php
$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"
}
  • 索引

  • MongoDB 手册中的listIndexes命令参考

  • MongoDB 手册中的索引文档

  • 枚举集合 规范

← MongoDB\Collection::insertOne()