Create index
public ensureIndex ( array $key, array $options = [] ) : |
||
$key | array | |
$options | array | see @link http://php.net/manual/en/mongocollection.ensureindex.php |
리턴 |
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)); }
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']); }