yii\mongodb\Collection::createIndex PHP Method

createIndex() public method

Creates an index on the collection and the specified fields.
public createIndex ( array | string $columns, array $options = [] ) : boolean
$columns array | string 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. 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, ] ```
$options array list of options in format: optionName => optionValue.
return boolean whether the operation successful.
    public function createIndex($columns, $options = [])
    {
        $index = array_merge(['key' => $columns], $options);
        return $this->database->createCommand()->createIndexes($this->name, [$index]);
    }