Skip to content

Commit

Permalink
PHPORM-50 PHPORM-65 Remove call to deprecated Collection::count for c…
Browse files Browse the repository at this point in the history
…ountDocuments (#18)

https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-count/

Fix pass options to countDocuments for transaction session
  • Loading branch information
GromNaN authored and alcaeus committed Aug 22, 2023
1 parent e045fab commit 4514964
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

1 comment on commit 4514964

@GromNaN
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue: #2626

Please sign in to comment.