Commit 6a17ac90 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-69: Index drop methods

parent 7b6b8e0a
......@@ -9,6 +9,7 @@ use MongoDB\Driver\Query;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\WriteConcern;
use InvalidArgumentException;
class Collection
{
......@@ -354,11 +355,21 @@ class Collection
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
* @param string $indexName
* @return Cursor
* @throws InvalidArgumentException if "*" is specified
* @throws InvalidArgumentException if "*" is specified, since dropIndexes()
* should be used to drop multiple indexes
*/
public function dropIndex($indexName)
{
// TODO
$indexName = (string) $indexName;
if ($indexName === '*') {
throw new InvalidArgumentException('dropIndexes() must be used to drop multiple indexes');
}
$command = new Command(array('dropIndexes' => $this->collname, 'index' => $indexName));
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
return $this->manager->executeCommand($this->dbname, $command, $readPreference);
}
/**
......@@ -370,7 +381,10 @@ class Collection
*/
public function dropIndexes()
{
// TODO
$command = new Command(array('dropIndexes' => $this->collname, 'index' => '*'));
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
return $this->manager->executeCommand($this->dbname, $command, $readPreference);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment