[SERVER-3337] $all with an empty array should return all documents rather than no documents Created: 26/Jun/11  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Moses Nakamura Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 1
Labels: logic, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-47374 Query with empty in clause performs c... Backlog
Assigned Teams:
Query Execution
Participants:

 Description   

$all doesn't work as expected on lists

The logic of all seems to be:
{field:{$all:lst}}
if for all x in list, x is in field, then return
else, do not return

However, for the empty list, which would vacuously satisfy everything, it does not return everything.



 Comments   
Comment by Asya Kamsky [ 15/Mar/22 ]

Since $in:[] returns nothing, I don't see how $all can behave differently...

Comment by David Storch [ 12/Jul/19 ]

The behavior of {$all: []} matching nothing has been in place for a long time, possibly since SERVER-143. It would definitely be a breaking change, although this could be a valuable change to help improve the consistency of MQL and avoid special cases in the semantics of the language. Since this behavior has been purposefully preserved over time to avoid impacting applications, I'm going to reclassify this ticket as "Improvement" rather than "Bug".

Comment by Jason R. Coombs [ 23/Mar/14 ]

I concur. Rather than raise an error, MongoDB should accept the empty list and treat it just like a list of empty queries.

Generated at Thu Feb 08 03:02:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.