-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
26 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,40 +282,40 @@ public function dump(mixed ...$args) | |
return $this; | ||
} | ||
|
||
private function getPipelineBuilder(): PipelineBuilder | ||
private function getAggregationBuilder(): AggregationBuilder | ||
{ | ||
$pipelineBuilder = new PipelineBuilder([], $this->collection, $this->options); | ||
$agg = new AggregationBuilder([], $this->collection, $this->options); | ||
|
||
$wheres = $this->compileWheres(); | ||
|
||
if (count($wheres)) { | ||
$pipelineBuilder->match(...$wheres); | ||
$agg->match(...$wheres); | ||
} | ||
|
||
// Distinct query | ||
if ($this->distinct) { | ||
// Return distinct results directly | ||
$column = $columns[0] ?? '_id'; | ||
Check failure on line 298 in src/Query/Builder.php GitHub Actions / analysis (8.1)
|
||
|
||
$pipelineBuilder->group( | ||
$agg->group( | ||
_id: \MongoDB\Builder\Expression::fieldPath($column), | ||
_document: Accumulator::first(Variable::root()), | ||
); | ||
$pipelineBuilder->replaceRoot( | ||
$agg->replaceRoot( | ||
newRoot: new FieldPath('_document'), | ||
); | ||
} | ||
|
||
if ($this->orders) { | ||
$pipelineBuilder->sort(...$this->orders); | ||
$agg->sort(...$this->orders); | ||
} | ||
|
||
if ($this->offset) { | ||
$pipelineBuilder->skip($this->offset); | ||
$agg->skip($this->offset); | ||
} | ||
|
||
if ($this->limit) { | ||
$pipelineBuilder->limit($this->limit); | ||
$agg->limit($this->limit); | ||
} | ||
|
||
// Normal query | ||
|
@@ -324,11 +324,11 @@ private function getPipelineBuilder(): PipelineBuilder | |
$columns = in_array('*', $this->columns) ? [] : $this->columns; | ||
$projection = array_fill_keys($columns, true) + $this->projections; | ||
if ($projection) { | ||
$pipelineBuilder->project(...$projection); | ||
$agg->project(...$projection); | ||
} | ||
} | ||
|
||
return $pipelineBuilder; | ||
return $agg; | ||
} | ||
|
||
/** | ||
|
@@ -594,7 +594,7 @@ public function generateCacheKey() | |
public function aggregate($function = null, $columns = []) | ||
Check failure on line 594 in src/Query/Builder.php GitHub Actions / analysis (8.1)
Check failure on line 594 in src/Query/Builder.php GitHub Actions / analysis (8.2)
|
||
{ | ||
if ($function === null) { | ||
return $this->getPipelineBuilder(); | ||
return $this->getAggregationBuilder(); | ||
} | ||
|
||
$this->aggregate = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters