[SERVER-1937] $gt/$lt/$ne with scalar operand yields inconsistent matches on arrays Created: 13/Oct/10  Updated: 06/Dec/22  Resolved: 12/Jul/19

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

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 3
Labels: query-44-grooming, query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server1937.js     File test.csv     File test.js    
Issue Links:
Depends
is depended on by SERVER-958 Range queries on arrays behave differ... Closed
Related
related to SERVER-3596 type bracketing used for $not query i... Closed
is related to SERVER-31876 $ne has inconsistent behavior Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

When the document in the collection contains an array:

{a: [1,10]}

and we run a non-equality query with a scalar operand, we see the following results:

{a: {$gt: 1}} -----> 1 document
{a: {$lt: 1}} -----> 0 document
{a: {$ne: 1}} -----> 0 document

> db.f.drop()
true
> db.f.save( {a:[1,10]} )
> db.f.find( {a:{$gt:1}} )
{ "_id" : ObjectId("4cb5fdb359001b4d0429c9de"), "a" : [ 1, 10 ] }
> db.f.find( {a:{$ne:1}} )
> 



 Comments   
Comment by David Storch [ 12/Jul/19 ]

This is working as designed. The operation {arrayField: {$ne: value}} has the same meaning as {$nor: [{arrayField: {$eq: value}}]}. That is, the expression means "match documents where the array does not contain value" as opposed to "match documents where the array has at least one element which is not equal to value".

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