From 3235940c6a4a97836c5d20dd03b5a4e26968272f Mon Sep 17 00:00:00 2001 From: verduck Date: Wed, 11 Sep 2024 15:25:05 +0900 Subject: [PATCH 1/2] Add options to countDocuments method --- src/Query/Builder.php | 2 +- tests/QueryTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 2bbd5a01a..43acbcc24 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -346,7 +346,7 @@ public function toMql(): array $aggregations = blank($this->aggregate['columns']) ? [] : $this->aggregate['columns']; if (in_array('*', $aggregations) && $function === 'count') { - $options = $this->inheritConnectionOptions(); + $options = $this->inheritConnectionOptions($this->options); return ['countDocuments' => [$wheres, $options]]; } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 1b5746842..78a7b1bee 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -660,4 +660,13 @@ public function testDelete(): void User::limit(null)->delete(); $this->assertEquals(0, User::count()); } + + public function testLimitCount(): void + { + $count = User::where('age', '>=', 20)->count(); + $this->assertEquals(7, $count); + + $count = User::where('age', '>=', 20)->options(['limit' => 3])->count(); + $this->assertEquals(3, $count); + } } From 1566f8c41efcf73fffbeec62bd86fee037b92b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 11 Sep 2024 09:53:34 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdedba537..d813edb5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. * Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124) * Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132) * Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137) +* Support options in `count()` queries by @verduck in [#3142](https://github.com/mongodb/laravel-mongodb/pull/3142) ## [4.8.0] - 2024-08-27