|
19 | 19 | use MongoDB\Operation\Count;
|
20 | 20 | use MongoDB\Operation\Distinct;
|
21 | 21 | use MongoDB\Operation\DropCollection;
|
| 22 | +use MongoDB\Operation\DropIndexes; |
22 | 23 | use MongoDB\Operation\FindOneAndDelete;
|
23 | 24 | use MongoDB\Operation\FindOneAndReplace;
|
24 | 25 | use MongoDB\Operation\FindOneAndUpdate;
|
@@ -366,43 +367,35 @@ public function drop()
|
366 | 367 | /**
|
367 | 368 | * Drop a single index in the collection.
|
368 | 369 | *
|
369 |
| - * @see http://docs.mongodb.org/manual/reference/command/dropIndexes/ |
370 |
| - * @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/ |
371 |
| - * @param string $indexName |
372 |
| - * @return Cursor |
| 370 | + * @param string $indexName Index name |
| 371 | + * @return object Command result document |
373 | 372 | * @throws InvalidArgumentException if $indexName is an empty string or "*"
|
374 | 373 | */
|
375 | 374 | public function dropIndex($indexName)
|
376 | 375 | {
|
377 | 376 | $indexName = (string) $indexName;
|
378 | 377 |
|
379 |
| - if ($indexName === '') { |
380 |
| - throw new InvalidArgumentException('Index name cannot be empty'); |
381 |
| - } |
382 |
| - |
383 | 378 | if ($indexName === '*') {
|
384 | 379 | throw new InvalidArgumentException('dropIndexes() must be used to drop multiple indexes');
|
385 | 380 | }
|
386 | 381 |
|
387 |
| - $command = new Command(array('dropIndexes' => $this->collname, 'index' => $indexName)); |
388 |
| - $readPreference = new ReadPreference(ReadPreference::RP_PRIMARY); |
| 382 | + $operation = new DropIndexes($this->dbname, $this->collname, $indexName); |
| 383 | + $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); |
389 | 384 |
|
390 |
| - return $this->manager->executeCommand($this->dbname, $command, $readPreference); |
| 385 | + return $operation->execute($server); |
391 | 386 | }
|
392 | 387 |
|
393 | 388 | /**
|
394 | 389 | * Drop all indexes in the collection.
|
395 | 390 | *
|
396 |
| - * @see http://docs.mongodb.org/manual/reference/command/dropIndexes/ |
397 |
| - * @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndexes/ |
398 |
| - * @return Cursor |
| 391 | + * @return object Command result document |
399 | 392 | */
|
400 | 393 | public function dropIndexes()
|
401 | 394 | {
|
402 |
| - $command = new Command(array('dropIndexes' => $this->collname, 'index' => '*')); |
403 |
| - $readPreference = new ReadPreference(ReadPreference::RP_PRIMARY); |
| 395 | + $operation = new DropIndexes($this->dbname, $this->collname, '*'); |
| 396 | + $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); |
404 | 397 |
|
405 |
| - return $this->manager->executeCommand($this->dbname, $command, $readPreference); |
| 398 | + return $operation->execute($server); |
406 | 399 | }
|
407 | 400 |
|
408 | 401 | /**
|
|
0 commit comments