MongoDB\Collection::dropIndex()
定义
参数
$indexName
: string|MongoDB\Model\IndexInfo
- 要删除的索引的名称或模型对象。使用
MongoDB\Collection::listIndexes()
方法查看集合上的现有索引。 $options
: array指定所需选项的数组。
返回值
一个包含dropIndexes
命令结果文档的数组或对象。返回类型将取决于typeMap
选项。
错误/异常
如果选项被使用且所选服务器不支持(例如collation
,readConcern
,writeConcern
),则抛出MongoDB\Exception\UnsupportedException
。
对于与参数或选项解析相关的错误,抛出MongoDB\Exception\InvalidArgumentException
。
MongoDB\Driver\Exception\RuntimeException 用于其他扩展级别的错误(例如连接错误)。
示例
以下示例将 borough_1
索引从 restaurants
集合在 test
数据库中删除
$collection = (new MongoDB\Client)->test->restaurants; $result = $collection->dropIndex('borough_1'); var_dump($result);
输出结果将类似于
object(MongoDB\Model\BSONDocument)#9 (1) { ["storage":"ArrayObject":private]=> array(2) { ["nIndexesWas"]=> int(2) ["ok"]=> float(1) } }
另请参阅
dropIndexes 命令参考 MongoDB 手册
索引文档 在 MongoDB 手册中