yii\mongodb\Command::createIndexes PHP Method

createIndexes() public method

Creates indexes in the collection.
public createIndexes ( string $collectionName, array[] $indexes ) : boolean
$collectionName string collection name.
$indexes array[] indexes specification. Each specification should be an array in format: optionName => value The main options are: - keys: array, column names with sort order, to be indexed. This option is mandatory. - unique: bool, whether to create unique index. - name: string, the name of the index, if not set it will be generated automatically. - background: bool, whether to bind index in the background. - sparse: bool, whether index should reference only documents with the specified field. See [[https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types]] for the full list of options.
return boolean whether operation was successful.
    public function createIndexes($collectionName, $indexes)
    {
        $this->document = $this->db->getQueryBuilder()->createIndexes($this->databaseName, $collectionName, $indexes);
        $result = current($this->execute()->toArray());
        return $result['ok'] > 0;
    }