[DRIVERS-2728] Document that countDocuments() uses $match and may not support the same filters as find/count commands Created: 20/Sep/23  Updated: 21/Sep/23

Status: Backlog
Project: Drivers
Component/s: CRUD
Fix Version/s: None

Type: Spec Change Priority: Unknown
Reporter: Jérôme Tamarelle Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by DRIVERS-501 Implement new count API Closed
is caused by PHPORM-50 Remove usage of the deprecated MongoD... Closed
Driver Changes: Needed

 Description   

Summary

Using the $where operator in countDocument filter is not supported.

As specified and implemented in drivers, the countDocuments operation uses an aggregation pipeline and copies the value of the filter argument into a $match stage.

If the filter contains a $where operator, a server error is returned.

MongoServerError: $where is not allowed in this context

This is an issue because the signature of find(filter, options) and countDocuments(filter, options) are the same. So users expect to be able to use the same filter for both methods.

Related discussion: https://github.com/mongodb/laravel-mongodb/discussions/2625

Motivation

Who is the affected end user?

Application developers

How does this affect the end user?

Yes, blocked.

How likely is it that this problem or use case will occur?

Everytime a developer tries to countDocuments on a find that they wrote using $where operator.

If the problem does occur, what are the consequences and how severe are they?

The command doesn't work. Developers must write their own aggregation pipeline or find a way to not use $where in the filter.

Is this issue urgent?

No

Is this ticket required by a downstream team?

No

Is this ticket only for tests?

No

Acceptance Criteria

Provide an helpful error message or update the generated aggregation pipeline so that $where can be used in countDocuments.



 Comments   
Comment by Jeremy Mikola [ 21/Sep/23 ]

This issue is not unique to $where, as it is only one of several restrictions when using $match (compared to typical query filters supported by find.

Proposed action for this issue would be to require drivers to document that countDocuments() uses an aggregation pipeline and reference the server docs for potential differences/restrictions between $match and filters supported by find.
 

Generated at Thu Feb 08 08:26:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.