36
36
37
37
class Collection
38
38
{
39
+ private static $ defaultTypeMap = [
40
+ 'array ' => 'MongoDB\Model\BSONArray ' ,
41
+ 'document ' => 'MongoDB\Model\BSONDocument ' ,
42
+ 'root ' => 'MongoDB\Model\BSONDocument ' ,
43
+ ];
39
44
private static $ wireVersionForFindAndModifyWriteConcern = 4 ;
40
45
41
46
private $ collectionName ;
@@ -102,7 +107,7 @@ public function __construct(Manager $manager, $namespace, array $options = [])
102
107
$ this ->manager = $ manager ;
103
108
$ this ->readConcern = isset ($ options ['readConcern ' ]) ? $ options ['readConcern ' ] : $ this ->manager ->getReadConcern ();
104
109
$ this ->readPreference = isset ($ options ['readPreference ' ]) ? $ options ['readPreference ' ] : $ this ->manager ->getReadPreference ();
105
- $ this ->typeMap = isset ($ options ['typeMap ' ]) ? $ options ['typeMap ' ] : null ;
110
+ $ this ->typeMap = isset ($ options ['typeMap ' ]) ? $ options ['typeMap ' ] : self :: $ defaultTypeMap ;
106
111
$ this ->writeConcern = isset ($ options ['writeConcern ' ]) ? $ options ['writeConcern ' ] : $ this ->manager ->getWriteConcern ();
107
112
}
108
113
@@ -340,11 +345,17 @@ public function distinct($fieldName, $filter = [], array $options = [])
340
345
/**
341
346
* Drop this collection.
342
347
*
343
- * @return object Command result document
348
+ * @see DropCollection::__construct() for supported options
349
+ * @param array $options Additional options
350
+ * @return array|object Command result document
344
351
*/
345
- public function drop ()
352
+ public function drop (array $ options = [] )
346
353
{
347
- $ operation = new DropCollection ($ this ->databaseName , $ this ->collectionName );
354
+ if ( ! isset ($ options ['typeMap ' ])) {
355
+ $ options ['typeMap ' ] = $ this ->typeMap ;
356
+ }
357
+
358
+ $ operation = new DropCollection ($ this ->databaseName , $ this ->collectionName , $ options );
348
359
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
349
360
350
361
return $ operation ->execute ($ server );
@@ -353,19 +364,25 @@ public function drop()
353
364
/**
354
365
* Drop a single index in the collection.
355
366
*
367
+ * @see DropIndexes::__construct() for supported options
356
368
* @param string $indexName Index name
357
- * @return object Command result document
369
+ * @param array $options Additional options
370
+ * @return array|object Command result document
358
371
* @throws InvalidArgumentException if $indexName is an empty string or "*"
359
372
*/
360
- public function dropIndex ($ indexName )
373
+ public function dropIndex ($ indexName, array $ options = [] )
361
374
{
362
375
$ indexName = (string ) $ indexName ;
363
376
364
377
if ($ indexName === '* ' ) {
365
378
throw new InvalidArgumentException ('dropIndexes() must be used to drop multiple indexes ' );
366
379
}
367
380
368
- $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , $ indexName );
381
+ if ( ! isset ($ options ['typeMap ' ])) {
382
+ $ options ['typeMap ' ] = $ this ->typeMap ;
383
+ }
384
+
385
+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , $ indexName , $ options );
369
386
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
370
387
371
388
return $ operation ->execute ($ server );
@@ -374,11 +391,17 @@ public function dropIndex($indexName)
374
391
/**
375
392
* Drop all indexes in the collection.
376
393
*
377
- * @return object Command result document
394
+ * @see DropIndexes::__construct() for supported options
395
+ * @param array $options Additional options
396
+ * @return array|object Command result document
378
397
*/
379
- public function dropIndexes ()
398
+ public function dropIndexes (array $ options = [] )
380
399
{
381
- $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , '* ' );
400
+ if ( ! isset ($ options ['typeMap ' ])) {
401
+ $ options ['typeMap ' ] = $ this ->typeMap ;
402
+ }
403
+
404
+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , '* ' , $ options );
382
405
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
383
406
384
407
return $ operation ->execute ($ server );
0 commit comments