Skip to content

Commit f1bdd1e

Browse files
committed
Update all Query\Builder tests to aggregation
1 parent bc3529a commit f1bdd1e

File tree

2 files changed

+641
-308
lines changed

2 files changed

+641
-308
lines changed

src/Query/Builder.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use MongoDB\Builder\Stage\GroupStage;
2929
use MongoDB\Builder\Stage\LimitStage;
3030
use MongoDB\Builder\Stage\MatchStage;
31+
use MongoDB\Builder\Stage\ProjectStage;
3132
use MongoDB\Builder\Stage\ReplaceRootStage;
3233
use MongoDB\Builder\Stage\SkipStage;
3334
use MongoDB\Builder\Stage\SortStage;
@@ -440,15 +441,8 @@ public function toMql(): array
440441
$projection = array_merge($projection, $this->projections);
441442
}
442443

443-
$options = [];
444-
445-
// Apply order, offset, limit and projection
446-
if ($this->timeout) {
447-
$options['maxTimeMS'] = $this->timeout * 1000;
448-
}
449-
450444
if ($this->orders) {
451-
$pipeline[] = new SortStage($this->orders);
445+
$pipeline[] = new SortStage(...$this->orders);
452446
}
453447

454448
if ($this->offset) {
@@ -459,23 +453,22 @@ public function toMql(): array
459453
$pipeline[] = new LimitStage($this->limit);
460454
}
461455

462-
if ($this->hint) {
463-
// @todo
464-
$options['hint'] = $this->hint;
465-
}
466-
467456
if ($projection) {
468-
$options['projection'] = $projection;
457+
$pipeline[] = new ProjectStage(...$projection);
469458
}
470459

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+
}
473465

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;
477468
}
478469

470+
$options = array_merge($options, $this->options);
471+
479472
$options = $this->inheritConnectionOptions($options);
480473

481474
$encoder = new BuilderEncoder();

0 commit comments

Comments
 (0)