Details
-
Bug
-
Resolution: Duplicate
-
Major - P3
-
None
-
1.6.5
-
None
-
osx 10.6.6
-
OS X
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(
)
> 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).