28
28
use MongoDB \Builder \Stage \GroupStage ;
29
29
use MongoDB \Builder \Stage \LimitStage ;
30
30
use MongoDB \Builder \Stage \MatchStage ;
31
+ use MongoDB \Builder \Stage \ProjectStage ;
31
32
use MongoDB \Builder \Stage \ReplaceRootStage ;
32
33
use MongoDB \Builder \Stage \SkipStage ;
33
34
use MongoDB \Builder \Stage \SortStage ;
@@ -440,15 +441,8 @@ public function toMql(): array
440
441
$ projection = array_merge ($ projection , $ this ->projections );
441
442
}
442
443
443
- $ options = [];
444
-
445
- // Apply order, offset, limit and projection
446
- if ($ this ->timeout ) {
447
- $ options ['maxTimeMS ' ] = $ this ->timeout * 1000 ;
448
- }
449
-
450
444
if ($ this ->orders ) {
451
- $ pipeline [] = new SortStage ($ this ->orders );
445
+ $ pipeline [] = new SortStage (... $ this ->orders );
452
446
}
453
447
454
448
if ($ this ->offset ) {
@@ -459,23 +453,22 @@ public function toMql(): array
459
453
$ pipeline [] = new LimitStage ($ this ->limit );
460
454
}
461
455
462
- if ($ this ->hint ) {
463
- // @todo
464
- $ options ['hint ' ] = $ this ->hint ;
465
- }
466
-
467
456
if ($ projection ) {
468
- $ options [ ' projection ' ] = $ projection ;
457
+ $ pipeline [ ] = new ProjectStage (... $ projection) ;
469
458
}
470
459
471
- // Fix for legacy support, converts the results to arrays instead of objects.
472
- $ options ['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
460
+ $ options = ['typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' ]];
461
+
462
+ if ($ this ->timeout ) {
463
+ $ options ['maxTimeMS ' ] = $ this ->timeout * 1000 ;
464
+ }
473
465
474
- // Add custom query options
475
- if (count ($ this ->options )) {
476
- $ options = array_merge ($ options , $ this ->options );
466
+ if ($ this ->hint ) {
467
+ $ options ['hint ' ] = $ this ->hint ;
477
468
}
478
469
470
+ $ options = array_merge ($ options , $ this ->options );
471
+
479
472
$ options = $ this ->inheritConnectionOptions ($ options );
480
473
481
474
$ encoder = new BuilderEncoder ();
0 commit comments