21
21
use Iterator ;
22
22
use MongoDB \BSON \JavascriptInterface ;
23
23
use MongoDB \Builder \BuilderEncoder ;
24
+ use MongoDB \Builder \Pipeline ;
24
25
use MongoDB \Codec \DocumentCodec ;
25
26
use MongoDB \Codec \Encoder ;
26
27
use MongoDB \Driver \CursorInterface ;
@@ -216,8 +217,9 @@ public function __toString()
216
217
* @throws InvalidArgumentException for parameter/option parsing errors
217
218
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
218
219
*/
219
- public function aggregate (array $ pipeline , array $ options = [])
220
+ public function aggregate (array | Pipeline $ pipeline , array $ options = [])
220
221
{
222
+ $ pipeline = $ this ->builderEncoder ->encodeIfSupported ($ pipeline );
221
223
$ hasWriteStage = is_last_pipeline_operator_write ($ pipeline );
222
224
223
225
$ options = $ this ->inheritReadPreference ($ options );
@@ -257,6 +259,7 @@ public function aggregate(array $pipeline, array $options = [])
257
259
*/
258
260
public function bulkWrite (array $ operations , array $ options = [])
259
261
{
262
+ // @todo encode each operation in $operations
260
263
$ options = $ this ->inheritWriteOptions ($ options );
261
264
$ options = $ this ->inheritCodec ($ options );
262
265
@@ -281,6 +284,7 @@ public function bulkWrite(array $operations, array $options = [])
281
284
*/
282
285
public function count (array |object $ filter = [], array $ options = [])
283
286
{
287
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
284
288
$ options = $ this ->inheritReadOptions ($ options );
285
289
286
290
$ operation = new Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
@@ -302,6 +306,7 @@ public function count(array|object $filter = [], array $options = [])
302
306
*/
303
307
public function countDocuments (array |object $ filter = [], array $ options = [])
304
308
{
309
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
305
310
$ options = $ this ->inheritReadOptions ($ options );
306
311
307
312
$ operation = new CountDocuments ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
@@ -439,6 +444,7 @@ public function createSearchIndexes(array $indexes, array $options = []): array
439
444
*/
440
445
public function deleteMany (array |object $ filter , array $ options = [])
441
446
{
447
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
442
448
$ options = $ this ->inheritWriteOptions ($ options );
443
449
444
450
$ operation = new DeleteMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
@@ -460,6 +466,7 @@ public function deleteMany(array|object $filter, array $options = [])
460
466
*/
461
467
public function deleteOne (array |object $ filter , array $ options = [])
462
468
{
469
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
463
470
$ options = $ this ->inheritWriteOptions ($ options );
464
471
465
472
$ operation = new DeleteOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
@@ -482,6 +489,7 @@ public function deleteOne(array|object $filter, array $options = [])
482
489
*/
483
490
public function distinct (string $ fieldName , array |object $ filter = [], array $ options = [])
484
491
{
492
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
485
493
$ options = $ this ->inheritReadOptions ($ options );
486
494
$ options = $ this ->inheritTypeMap ($ options );
487
495
@@ -640,6 +648,7 @@ public function explain(Explainable $explainable, array $options = [])
640
648
*/
641
649
public function find (array |object $ filter = [], array $ options = [])
642
650
{
651
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
643
652
$ options = $ this ->inheritReadOptions ($ options );
644
653
$ options = $ this ->inheritCodecOrTypeMap ($ options );
645
654
@@ -662,6 +671,7 @@ public function find(array|object $filter = [], array $options = [])
662
671
*/
663
672
public function findOne (array |object $ filter = [], array $ options = [])
664
673
{
674
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
665
675
$ options = $ this ->inheritReadOptions ($ options );
666
676
$ options = $ this ->inheritCodecOrTypeMap ($ options );
667
677
@@ -687,6 +697,7 @@ public function findOne(array|object $filter = [], array $options = [])
687
697
*/
688
698
public function findOneAndDelete (array |object $ filter , array $ options = [])
689
699
{
700
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
690
701
$ options = $ this ->inheritWriteOptions ($ options );
691
702
$ options = $ this ->inheritCodecOrTypeMap ($ options );
692
703
@@ -717,6 +728,7 @@ public function findOneAndDelete(array|object $filter, array $options = [])
717
728
*/
718
729
public function findOneAndReplace (array |object $ filter , array |object $ replacement , array $ options = [])
719
730
{
731
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
720
732
$ options = $ this ->inheritWriteOptions ($ options );
721
733
$ options = $ this ->inheritCodecOrTypeMap ($ options );
722
734
@@ -747,6 +759,7 @@ public function findOneAndReplace(array|object $filter, array|object $replacemen
747
759
*/
748
760
public function findOneAndUpdate (array |object $ filter , array |object $ update , array $ options = [])
749
761
{
762
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
750
763
$ options = $ this ->inheritWriteOptions ($ options );
751
764
$ options = $ this ->inheritCodecOrTypeMap ($ options );
752
765
@@ -995,6 +1008,7 @@ public function rename(string $toCollectionName, ?string $toDatabaseName = null,
995
1008
*/
996
1009
public function replaceOne (array |object $ filter , array |object $ replacement , array $ options = [])
997
1010
{
1011
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
998
1012
$ options = $ this ->inheritWriteOptions ($ options );
999
1013
$ options = $ this ->inheritCodec ($ options );
1000
1014
@@ -1018,6 +1032,7 @@ public function replaceOne(array|object $filter, array|object $replacement, arra
1018
1032
*/
1019
1033
public function updateMany (array |object $ filter , array |object $ update , array $ options = [])
1020
1034
{
1035
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
1021
1036
$ options = $ this ->inheritWriteOptions ($ options );
1022
1037
1023
1038
$ operation = new UpdateMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
@@ -1040,6 +1055,7 @@ public function updateMany(array|object $filter, array|object $update, array $op
1040
1055
*/
1041
1056
public function updateOne (array |object $ filter , array |object $ update , array $ options = [])
1042
1057
{
1058
+ $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
1043
1059
$ options = $ this ->inheritWriteOptions ($ options );
1044
1060
1045
1061
$ operation = new UpdateOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
@@ -1077,6 +1093,7 @@ public function updateSearchIndex(string $name, array|object $definition, array
1077
1093
*/
1078
1094
public function watch (array $ pipeline = [], array $ options = [])
1079
1095
{
1096
+ $ pipeline = $ this ->builderEncoder ->encodeIfSupported ($ pipeline );
1080
1097
$ options = $ this ->inheritReadOptions ($ options );
1081
1098
$ options = $ this ->inheritCodecOrTypeMap ($ options );
1082
1099
0 commit comments