From 121db8e10e36d27ab0eb9c570efb5117301c5eb6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 31 Oct 2024 16:58:32 +0100 Subject: [PATCH] DRIVERS-2728: Document query limitations in countDocuments API (#1701) --- source/crud/crud.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/crud/crud.md b/source/crud/crud.md index cce5aede63..f28a07ed31 100644 --- a/source/crud/crud.md +++ b/source/crud/crud.md @@ -762,6 +762,11 @@ if (limit) { pipeline.push({'$group': {'_id': 1, 'n': {'$sum': 1}}}) ``` +Due to countDocuments using the `$match` aggregation pipeline stage, certain query operators cannot be used in +countDocuments. This includes the `$where` and `$near` query operators, among others. Drivers MUST document these +[restrictions](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#restrictions) in their +documentation. + The count of documents is returned in the `n` field, similar to the `count` command. countDocuments options other than filter, skip, and limit are added as options to the `aggregate` command. @@ -2474,6 +2479,8 @@ aforementioned allowance in the SemVer spec. ## Changelog +- 2024-10-30: Document query limitations in `countDocuments`. + - 2024-10-01: Add sort option to `replaceOne` and `updateOne`. - 2024-09-12: Specify that explain helpers support maxTimeMS.