Webiny\Component\Mongo\Mongo::createIndex PHP Method

createIndex() public method

public createIndex ( $collectionName, Webiny\Component\Mongo\Index\IndexInterface $index, array $options = [] )
$index Webiny\Component\Mongo\Index\IndexInterface
$options array
    public function createIndex($collectionName, IndexInterface $index, array $options = [])
    {
        return $this->bridge->createIndex($this->cName($collectionName), $index->getFields(), $index->getOptions() + $options);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @dataProvider driverSet
  */
 public function testSingleIndex(Mongo $mongo)
 {
     $collection = 'TestIndexCollection';
     $mongo->dropCollection($collection);
     $index = new SingleIndex('Name', 'name', false, true);
     $mongo->createIndex($collection, $index);
     $index = new CompoundIndex('TitleCategory', ['title', 'category']);
     $mongo->createIndex($collection, $index);
     $index = new TextIndex('Title', ['title', 'category']);
     $mongo->createIndex($collection, $index);
     $indexes = $mongo->getIndexInfo($collection);
     $this->assertEquals(4, count($indexes));
 }
All Usage Examples Of Webiny\Component\Mongo\Mongo::createIndex