[SERVER-36681] Change {$ne: null} semantics to be more intuitive Created: 15/Aug/18  Updated: 12/Sep/23

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

Type: Task Priority: Major - P3
Reporter: Ian Boros Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 2
Labels: asya, mql-semantics
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-42464 Find query fails with filter on field... Closed
Related
related to SERVER-31876 $ne has inconsistent behavior Closed
is related to SERVER-36635 Inconsistent query results with and w... Backlog
is related to SERVER-67506 [CQF] Dotted path equality to null in... Open
is related to SERVER-36465 Non-multikey sparse indexes can be us... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Major Change
Participants:

 Description   

{$ne: null} has some counterintuitive behavior which has hurt us several times now:

db.c.insert({a: [1, {c: 1}]});
db.c.insert({a: [1]});
 
db.c.find({"a.b": {$exists: true}}) // Returns nothing.
db.c.find({"a.b": {$ne: null}}) // Returns {a: [1]} !!!!

That is, {$ne: null} doesn't necessarily return a subset of the things that {$exists: true} returns. This ticket is to track the work of changing the meaning of {$ne: null}.



 Comments   
Comment by Asya Kamsky [ 17/Aug/18 ]

Just re-checked on latest - in fact, that was fixed via SERVER-27646 for a regular index.

Comment by Charlie Swanson [ 17/Aug/18 ]

asya I think that behavior was a bug, and I think I fixed it when I implemented SERVER-27646. The presence of an index no longer affects the results of that query when I test on master.

Comment by Asya Kamsky [ 17/Aug/18 ]

Note that it only returns this in absence of an index in versions 4.0 and earlier.

With index on "a.b":

db.c.find({"a.b":{$ne:null}})  /* returns nothing */

Without index:

db.c.find({"a.b":{$ne:null}})
{ "_id" : ObjectId("5b76dd86789c80f826931db1"), "a" : [ 1 ] }

Is this really $ne to null semantics or just a bug somewhere (similar to SERVER-36635)?

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