deleteIndex() 공개 메소드

Deletes an index from this collection
public deleteIndex ( string | array $keys ) : array
$keys string | array Field or fields from which to delete the index.
리턴 array Returns the database response.
예제 #1
0
 /**
  * Indicate that the given index should be dropped.
  *
  * @param  string|array  $columns
  * @return Blueprint
  */
 public function dropIndex($columns = null)
 {
     $columns = $this->fluent($columns);
     // Columns are passed as a default array.
     if (is_array($columns) && is_int(key($columns))) {
         // Transform the columns to the required array format.
         $transform = array();
         foreach ($columns as $column) {
             $transform[$column] = 1;
         }
         $columns = $transform;
     }
     $this->collection->deleteIndex($columns);
     return $this;
 }
    public function testDeleteIndex() {
      $idx = $this->object->db->selectCollection('system.indexes');

      $this->object->ensureIndex('foo');
      $this->object->ensureIndex(array('foo' => -1));

      $cursor = $idx->find(array('ns' => 'phpunit.c'));
      $num = iterator_count($cursor);
      $this->assertEquals(3, $num);

      $this->object->deleteIndex(null);
      $num = iterator_count($idx->find(array('ns' => 'phpunit.c')));
      $this->assertEquals(3, $num);

      $this->object->deleteIndex(array('foo' => 1));
      $num = iterator_count($idx->find(array('ns' => 'phpunit.c')));
      $this->assertEquals(2, $num);

      $this->object->deleteIndex('foo');
      $num = iterator_count($idx->find(array('ns' => 'phpunit.c')));
      $this->assertEquals(2, $num);

      $this->object->deleteIndex(array('foo' => -1));
      $num = iterator_count($idx->find(array('ns' => 'phpunit.c')));
      $this->assertEquals(1, $num);
    }
예제 #3
0
 /**
  * deleteIndex.
  */
 public function deleteIndex($keys)
 {
     $this->time->start();
     $return = parent::deleteIndex($keys);
     $time = $this->time->stop();
     $this->log(array('type' => 'deleteIndex', 'keys' => $keys, 'time' => $time));
     return $return;
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     $db = \DB::getMongoDB();
     $statementsCollection = new MongoCollection($db, 'statements');
     $statementsCollection->deleteIndex('stored');
     $statementsCollection->deleteIndex(['lrs_id' => 1, 'stored' => -1]);
     $statementsCollection->update([], ['$unset' => ["stored" => ""]], ['multiple' => true]);
     $statementsCursor = $statementsCollection->find();
     $remaining = $statementsCursor->count();
     print $remaining . ' statements total' . PHP_EOL;
     $maxBatchSize = 10000;
     while ($statementsCursor->hasNext()) {
         $batch = new MongoUpdateBatch($statementsCollection);
         $batchSize = 0;
         $shouldExecute = false;
         while ($batchSize < $maxBatchSize && $statementsCursor->hasNext()) {
             $batchSize++;
             $statement = $statementsCursor->next();
             if (isset($statement['refs'])) {
                 $query = ['q' => ['_id' => $statement['_id']], 'u' => ['$set' => []], 'multi' => false, 'upsert' => false];
                 foreach ($statement['refs'] as $key => $refStatement) {
                     if (isset($refStatement['timestamp']) && $refStatement['timestamp'] instanceof MongoDate) {
                         $query['u']['$set']['refs.' . $key . '.timestamp'] = date('Y-m-d\\TH:i:s.uP', $refStatement['timestamp']->sec);
                     }
                     if (isset($refStatement['stored']) && $refStatement['stored'] instanceof MongoDate) {
                         $query['u']['$set']['refs.' . $key . '.stored'] = date('Y-m-d\\TH:i:s.uP', $refStatement['stored']->sec);
                     }
                 }
                 if (!empty($query['u']['$set'])) {
                     $batch->add((object) $query);
                     $shouldExecute = true;
                 }
             }
         }
         if ($shouldExecute) {
             $batch->execute();
         }
         $remaining -= $batchSize;
         print $remaining . ' remaining' . PHP_EOL;
     }
 }
 public function testDeleteIndexBroken()
 {
     $idx = $this->object->db->selectCollection('system.indexes');
     $this->object->ensureIndex('foo');
     $this->object->ensureIndex(array('foo' => -1));
     $cursor = $idx->find(array('ns' => 'phpunit.c'));
     $num = iterator_count($cursor);
     $this->assertEquals(3, $num);
     set_error_handler(array('MongoCollectionTest', 'errorHandler'));
     try {
         $this->object->deleteIndex(null);
     } catch (Exception $e) {
         $this->assertEquals("HANDLED: MongoCollection::deleteIndex(): The key needs to be either a string or an array", $e->getMessage());
     }
     restore_error_handler();
     $num = iterator_count($idx->find(array('ns' => 'phpunit.c')));
     $this->assertEquals(3, $num);
 }
예제 #6
0
 /**
  * Wrapper method for MongoCollection::deleteIndex().
  *
  * @see http://php.net/manual/en/mongocollection.deleteindex.php
  * @param array|string $keys
  * @return array
  */
 public function deleteIndex($keys)
 {
     return $this->mongoCollection->deleteIndex($keys);
 }
예제 #7
0
 /**
  * @param $name
  *
  * @return array
  */
 public function dropIndex($name)
 {
     return $this->collection->deleteIndex($name);
 }