[SERVER-2470] sort (using an index + $exists) incorrectly excluding results Created: 02/Feb/11  Updated: 17/Mar/11  Resolved: 02/Feb/11

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 1.6.5
Fix Version/s: None

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

osx 10.6.6


Operating System: OS X
Participants:

 Description   

our queries with sorts aren't returning results that really should be returned. I believe this happens when the index used by the sort doesn't include the record(s) that should be returned. here's a simple way to reproduce the problem:

> db.version()
1.6.5
> db.foo.insert(

{a: 1, b: 2}

)

> db.foo.find({}).sort(

{c: -1}

)

{ "_id" : ObjectId("4d49a87bff97b37303687cfa"), "a" : 1, "b" : 2 }

// all ok so far

> db.foo.find({c: {$exists: false}}).sort(

{c: -1}

)

{ "_id" : ObjectId("4d49a87bff97b37303687cfa"), "a" : 1, "b" : 2 }

// still ok

> db.foo.ensureIndex(

{c: -1}

) // now we have an index on the sort key

> db.foo.find({c: {$exists: false}}).sort(

{c: -1}

) // which makes my result disappear

> db.foo.find({}).sort(

{c: -1}

) // still ok without the $exists

{ "_id" : ObjectId("4d49a87bff97b37303687cfa"), "a" : 1, "b" : 2 }

> db.foo.find({c: {$not: {$exists: true}}}).sort(

{c: -1}

) // and ok with a convoluted $not $exists

{ "_id" : ObjectId("4d49a87bff97b37303687cfa"), "a" : 1, "b" : 2 }

this didn't happen in 10.6.3 (not sure in 10.6.4).



 Comments   
Comment by Visnu Pitiyanuvath [ 02/Feb/11 ]

leaving closed and left a comment on SERVER-1587. re-checked and also broken in 1.6.3.

Comment by Aaron Staple [ 02/Feb/11 ]

Probably the same as SERVER-1587. Please reopen if that's not the case. (If you're sure it's not happening on 1.6.3 that would be unexpected since SERVER-1587 has been around for a while.)

Comment by Visnu Pitiyanuvath [ 02/Feb/11 ]

sorry, that should read "this didn't happen in 1.6.3 (not sure in 1.6.4)." I was clarifying mongodb versions, not osx versions.

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