/**
  * Deletes an index from this collection
  *
  * @link http://www.php.net/manual/en/mongocollection.deleteindex.php
  * @param string|array $keys Field or fields from which to delete the index.
  * @return array Returns the database response.
  */
 public function deleteIndex($keys)
 {
     if (is_string($keys)) {
         $indexName = $keys;
     } elseif (is_array($keys)) {
         $indexName = \MongoDB\generate_index_name($keys);
     } else {
         throw new \InvalidArgumentException();
     }
     return TypeConverter::toLegacy($this->collection->dropIndex($indexName));
 }
Exemplo n.º 2
0
 /**
  * Deletes an index from this collection
  *
  * @link http://www.php.net/manual/en/mongocollection.deleteindex.php
  * @param string|array $keys Field or fields from which to delete the index.
  * @return array Returns the database response.
  */
 public function deleteIndex($keys)
 {
     if (is_string($keys)) {
         $indexName = $keys;
         if (!preg_match('#_-?1$#', $indexName)) {
             $indexName .= '_1';
         }
     } elseif (is_array($keys)) {
         $indexName = \MongoDB\generate_index_name($keys);
     } else {
         throw new \InvalidArgumentException();
     }
     try {
         return TypeConverter::toLegacy($this->collection->dropIndex($indexName));
     } catch (\MongoDB\Driver\Exception\Exception $e) {
         return ExceptionConverter::toResultArray($e) + ['nIndexesWas' => count($this->getIndexInfo())];
     }
 }