public function testDropAllIndexesByWildcard()
 {
     $indexes = [['key' => ['x' => 1]], ['key' => ['y' => 1]]];
     $operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);
     $createdIndexNames = $operation->execute($this->getPrimaryServer());
     $this->assertSame('x_1', $createdIndexNames[0]);
     $this->assertSame('y_1', $createdIndexNames[1]);
     $this->assertIndexExists('x_1');
     $this->assertIndexExists('y_1');
     $operation = new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), '*');
     $this->assertCommandSucceeded($operation->execute($this->getPrimaryServer()));
     $operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName());
     $indexes = $operation->execute($this->getPrimaryServer());
     foreach ($indexes as $index) {
         if ($index->getName() === 'x_1') {
             $this->fail('The "x_1" index should have been deleted');
         }
         if ($index->getName() === 'y_1') {
             $this->fail('The "y_1" index should have been deleted');
         }
     }
 }
示例#2
0
 /**
  * Drop all indexes in the collection.
  *
  * @return object Command result document
  */
 public function dropIndexes()
 {
     $operation = new DropIndexes($this->databaseName, $this->collectionName, '*');
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }
示例#3
0
 /**
  * Drop all indexes in the collection.
  *
  * @see DropIndexes::__construct() for supported options
  * @param array $options Additional options
  * @return array|object Command result document
  */
 public function dropIndexes(array $options = [])
 {
     if (!isset($options['typeMap'])) {
         $options['typeMap'] = $this->typeMap;
     }
     $operation = new DropIndexes($this->databaseName, $this->collectionName, '*', $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }