Skip to content

Commit 25a6e9e

Browse files
authored
Add options to countDocuments method (#3142)
1 parent aebf049 commit 25a6e9e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
1111
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
1212
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
1313
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
14+
* Support options in `count()` queries by @verduck in [#3142](https://github.com/mongodb/laravel-mongodb/pull/3142)
1415

1516
## [4.8.0] - 2024-08-27
1617

src/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function toMql(): array
346346
$aggregations = blank($this->aggregate['columns']) ? [] : $this->aggregate['columns'];
347347

348348
if (in_array('*', $aggregations) && $function === 'count') {
349-
$options = $this->inheritConnectionOptions();
349+
$options = $this->inheritConnectionOptions($this->options);
350350

351351
return ['countDocuments' => [$wheres, $options]];
352352
}

tests/QueryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,13 @@ public function testDelete(): void
660660
User::limit(null)->delete();
661661
$this->assertEquals(0, User::count());
662662
}
663+
664+
public function testLimitCount(): void
665+
{
666+
$count = User::where('age', '>=', 20)->count();
667+
$this->assertEquals(7, $count);
668+
669+
$count = User::where('age', '>=', 20)->options(['limit' => 3])->count();
670+
$this->assertEquals(3, $count);
671+
}
663672
}

0 commit comments

Comments
 (0)