Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-2470

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 1.6.5
    • Index Maintenance
    • 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(

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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: