ensureIndex() public method

Create index
Deprecation: since 1.19 Use self::createIndex()
public ensureIndex ( array $key, array $options = [] ) : Collection
$key array
$options array see @link http://php.net/manual/en/mongocollection.ensureindex.php
return Collection
Esempio n. 1
0
 public function testDeleteIndex()
 {
     $this->collection->ensureIndex(array('asc' => 1, 'desc' => -1));
     $this->collection->deleteIndex(array('asc' => 1, 'desc' => -1));
     $indexes = $this->collection->getIndexes();
     $this->assertEquals(1, count($indexes));
 }
Esempio n. 2
0
 public function testHint()
 {
     // create index
     $this->collection->ensureIndex(array('a' => 1));
     $this->collection->ensureIndex(array('a' => 1, 'b' => 1));
     // add documents
     $this->collection->insert(array('a' => 1))->insert(array('a' => 1, 'b' => 1));
     // without hint
     $explainWithoutHint = $this->collection->find()->where('a', 1)->explain();
     // with hint
     $explainWithHint = $this->collection->find()->hint(array('a' => 1, 'b' => 1))->where('a', 1)->explain();
     $currentVersion = $this->collection->getDatabase()->getClient()->getDbVersion();
     if (version_compare($currentVersion, '3', '<')) {
         $this->assertEquals('BtreeCursor a_1', $explainWithoutHint['cursor']);
         $this->assertEquals('BtreeCursor a_1_b_1', $explainWithHint['cursor']);
     } else {
         $this->assertEquals('a_1', $explainWithoutHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
         $this->assertEquals('a_1_b_1', $explainWithHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
     }
 }
 public function testEnsureIndex()
 {
     $this->collection->ensureIndex(array('asc' => 1, 'desc' => -1));
     $indexes = $this->collection->getIndexes();
     $this->assertEquals(array('asc' => 1, 'desc' => -1), $indexes[1]['key']);
 }