3636
3737class Collection
3838{
39+ private static $ defaultTypeMap = [
40+ 'array ' => 'MongoDB\Model\BSONArray ' ,
41+ 'document ' => 'MongoDB\Model\BSONDocument ' ,
42+ 'root ' => 'MongoDB\Model\BSONDocument ' ,
43+ ];
3944 private static $ wireVersionForFindAndModifyWriteConcern = 4 ;
4045
4146 private $ collectionName ;
@@ -102,7 +107,7 @@ public function __construct(Manager $manager, $namespace, array $options = [])
102107 $ this ->manager = $ manager ;
103108 $ this ->readConcern = isset ($ options ['readConcern ' ]) ? $ options ['readConcern ' ] : $ this ->manager ->getReadConcern ();
104109 $ 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 ;
106111 $ this ->writeConcern = isset ($ options ['writeConcern ' ]) ? $ options ['writeConcern ' ] : $ this ->manager ->getWriteConcern ();
107112 }
108113
@@ -340,11 +345,17 @@ public function distinct($fieldName, $filter = [], array $options = [])
340345 /**
341346 * Drop this collection.
342347 *
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
344351 */
345- public function drop ()
352+ public function drop (array $ options = [] )
346353 {
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 );
348359 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
349360
350361 return $ operation ->execute ($ server );
@@ -353,19 +364,25 @@ public function drop()
353364 /**
354365 * Drop a single index in the collection.
355366 *
367+ * @see DropIndexes::__construct() for supported options
356368 * @param string $indexName Index name
357- * @return object Command result document
369+ * @param array $options Additional options
370+ * @return array|object Command result document
358371 * @throws InvalidArgumentException if $indexName is an empty string or "*"
359372 */
360- public function dropIndex ($ indexName )
373+ public function dropIndex ($ indexName, array $ options = [] )
361374 {
362375 $ indexName = (string ) $ indexName ;
363376
364377 if ($ indexName === '* ' ) {
365378 throw new InvalidArgumentException ('dropIndexes() must be used to drop multiple indexes ' );
366379 }
367380
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 );
369386 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
370387
371388 return $ operation ->execute ($ server );
@@ -374,11 +391,17 @@ public function dropIndex($indexName)
374391 /**
375392 * Drop all indexes in the collection.
376393 *
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
378397 */
379- public function dropIndexes ()
398+ public function dropIndexes (array $ options = [] )
380399 {
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 );
382405 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
383406
384407 return $ operation ->execute ($ server );
0 commit comments