Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

PHPORM-50 PHPORM-65 Remove call to deprecated Collection::count for countDocuments #18

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Throw an exception when `Query\Builder::orderBy()` is used with invalid direction [#7](https://github.com/GromNaN/laravel-mongodb-private/pull/7) by [@GromNaN](https://github.com/GromNaN).
- Throw an exception when `Query\Builder::push()` is used incorrectly [#5](https://github.com/GromNaN/laravel-mongodb-private/pull/5) by [@GromNaN](https://github.com/GromNaN).
- Remove public property `Query\Builder::$paginating` [#15](https://github.com/GromNaN/laravel-mongodb-private/pull/15) by [@GromNaN](https://github.com/GromNaN).
- Remove call to deprecated `Collection::count` for `countDocuments` [#18](https://github.com/GromNaN/laravel-mongodb-private/pull/18) by [@GromNaN](https://github.com/GromNaN).

## [3.9.2] - 2022-09-01

Expand Down
8 changes: 5 additions & 3 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ public function toMql(): array
$aggregations = blank($this->aggregate['columns']) ? [] : $this->aggregate['columns'];

if (in_array('*', $aggregations) && $function == 'count') {
return ['count' => [$wheres, []]];
$options = $this->inheritConnectionOptions();

return ['countDocuments' => [$wheres, $options]];
} elseif ($function == 'count') {
// Translate count into sum.
$group['aggregate'] = ['$sum' => 1];
Expand Down Expand Up @@ -329,7 +331,7 @@ public function toMql(): array

$options = $this->inheritConnectionOptions();

return ['distinct' => [$column, $wheres ?: [], $options]];
return ['distinct' => [$column, $wheres, $options]];
} // Normal query
else {
// Convert select columns to simple projections.
Expand Down Expand Up @@ -396,7 +398,7 @@ public function getFresh($columns = [], $returnLazy = false)
$this->columns = [];
}

$command = $this->toMql($columns);
$command = $this->toMql();
assert(count($command) >= 1, 'At least one method call is required to execute a query');

$result = $this->collection;
Expand Down