yii\mongodb\Collection::dropIndex PHP Метод

dropIndex() публичный Метод

Drop indexes for specified column(s).
public dropIndex ( string | array $columns ) : boolean
$columns string | array column name or list of column names. If array is given, each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort. Use value 'text' to specify text index. You can specify field using native numeric key with the field name as a value, in this case ascending sort will be used. For example: ```php [ 'name', 'status' => -1, 'description' => 'text', ] ```
Результат boolean whether the operation successful.
    public function dropIndex($columns)
    {
        $existingIndexes = $this->listIndexes();
        $indexKey = $this->database->connection->getQueryBuilder()->buildSortFields($columns);
        foreach ($existingIndexes as $index) {
            if ($index['key'] == $indexKey) {
                $this->database->createCommand()->dropIndexes($this->name, $index['name']);
                return true;
            }
        }
        throw new Exception('Index to be dropped does not exist.');
    }