[SERVER-8026] When an index is present, $not operator doesn't return documents that don't contain this field Created: 24/Dec/12  Updated: 15/Feb/13  Resolved: 26/Dec/12

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

Type: Bug Priority: Major - P3
Reporter: Guy Zyskind Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-7261 field range with $not should properly... Closed
Operating System: ALL
Steps To Reproduce:

// 1. Insert these 3 rows:
db.testNotIndex.insert(

{"date": ISODate("2012-12-21T16:03:08.428Z") }

)
db.testNotIndex.insert(

{"date": ISODate("2012-12-21T17:03:08.428Z") }

)
db.testNotIndex.insert(

{"a": 1 }

)

// 2. Without an index, 2 results are returned as expected for 'd'
var d = ISODate("2012-12-21T17:33:08.428Z");
var c1 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} });

// 3. Using an index, only 1 result is returned when issuing the same query. Documents without the 'date' field are ignored.
db.testNotIndex.ensureIndex(

{date: 1}

)
var c2 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} });

// ( 2 == 1 ) == false
assert( c1 == c2 );

Participants:

 Description   

When using the $not operator on an indexed 'date' field, only documents that contain this field are returned, while documents that do not contain this field (and should therefore be returned), are ignored.

Please see steps to reproduce for details.



 Comments   
Comment by Aaron Staple [ 26/Dec/12 ]

Hi Guy - This is a duplicate of SERVER-7261.

Comment by Guy Zyskind [ 24/Dec/12 ]

Currently my workaround is to use $or with 1. $exists: false, 2. $gt/$lt.

Unfortunately, this appears to significantly reduce performance, so a fix to this bug is still necessary.

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