sort (using an index + $exists) incorrectly excluding results

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.6.5
    • Component/s: Index Maintenance
    • None
    • Environment:
      osx 10.6.6
    • OS X
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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).

            Assignee:
            Unassigned
            Reporter:
            Visnu Pitiyanuvath
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: