9
9
use MongoDB \Driver \ReadPreference ;
10
10
use MongoDB \Driver \BulkWrite ;
11
11
use MongoDB \Driver \WriteConcern ;
12
+ use InvalidArgumentException ;
12
13
13
14
class Collection
14
15
{
@@ -354,11 +355,21 @@ public function drop()
354
355
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
355
356
* @param string $indexName
356
357
* @return Cursor
357
- * @throws InvalidArgumentException if "*" is specified
358
+ * @throws InvalidArgumentException if "*" is specified, since dropIndexes()
359
+ * should be used to drop multiple indexes
358
360
*/
359
361
public function dropIndex ($ indexName )
360
362
{
361
- // TODO
363
+ $ indexName = (string ) $ indexName ;
364
+
365
+ if ($ indexName === '* ' ) {
366
+ throw new InvalidArgumentException ('dropIndexes() must be used to drop multiple indexes ' );
367
+ }
368
+
369
+ $ command = new Command (array ('dropIndexes ' => $ this ->collname , 'index ' => $ indexName ));
370
+ $ readPreference = new ReadPreference (ReadPreference::RP_PRIMARY );
371
+
372
+ return $ this ->manager ->executeCommand ($ this ->dbname , $ command , $ readPreference );
362
373
}
363
374
364
375
/**
@@ -370,7 +381,10 @@ public function dropIndex($indexName)
370
381
*/
371
382
public function dropIndexes ()
372
383
{
373
- // TODO
384
+ $ command = new Command (array ('dropIndexes ' => $ this ->collname , 'index ' => '* ' ));
385
+ $ readPreference = new ReadPreference (ReadPreference::RP_PRIMARY );
386
+
387
+ return $ this ->manager ->executeCommand ($ this ->dbname , $ command , $ readPreference );
374
388
}
375
389
376
390
/**
0 commit comments