[SERVER-12877] $Not with non-existing fields change in 2.6 from 2.4 Created: 25/Feb/14  Updated: 10/Dec/14  Resolved: 17/Jul/14

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

Type: Bug Priority: Major - P3
Reporter: Andrew Emil (Inactive) Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

//2.4
db.test.insert({_id:0})
db.test.find({a:{$not: {$lt: null}}})
//nothing returned

//2.6
db.test.insert({_id:0})
db.test.find({a:{$not: {$lt: null}}})
{_id: 0}

Note that this works with $lt:1 or any other value, not just null



 Comments   
Comment by David Storch [ 17/Jul/14 ]

This is a bug in 2.4 that has been fixed for 2.6.

find({a: {$not: {$lt: <value>}}}) does not mean the same thing as find({a: {$gte: <value>}}). If <value> is a number, for example, then the former will match numbers greater than or equal to <value> as well as non-numbers. The latter will only match numbers greater than or equal to <value>.

You should think of $not as complementing your result set. So since the document in the example above does not match the query db.test.find({a: {$lt: null}}) it should match db.test.find({a:{$not: {$lt: null}}}).

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