Skip to content

Commit 121db8e

Browse files
authored
DRIVERS-2728: Document query limitations in countDocuments API (#1701)
1 parent 5f6fd28 commit 121db8e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

source/crud/crud.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ if (limit) {
762762
pipeline.push({'$group': {'_id': 1, 'n': {'$sum': 1}}})
763763
```
764764
765+
Due to countDocuments using the `$match` aggregation pipeline stage, certain query operators cannot be used in
766+
countDocuments. This includes the `$where` and `$near` query operators, among others. Drivers MUST document these
767+
[restrictions](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#restrictions) in their
768+
documentation.
769+
765770
The count of documents is returned in the `n` field, similar to the `count` command. countDocuments options other than
766771
filter, skip, and limit are added as options to the `aggregate` command.
767772
@@ -2474,6 +2479,8 @@ aforementioned allowance in the SemVer spec.
24742479
24752480
## Changelog
24762481
2482+
- 2024-10-30: Document query limitations in `countDocuments`.
2483+
24772484
- 2024-10-01: Add sort option to `replaceOne` and `updateOne`.
24782485
24792486
- 2024-09-12: Specify that explain helpers support maxTimeMS.

0 commit comments

Comments
 (0)