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

make sparse indexes error out on {$exists: false} queries

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.1.2
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Major Change
    • Operating System:
      ALL

      Description

      When querying for documents in which a field does not exist, the optimiser will consider using a sparse index on that field, but this means that it will never find anything.

      > db.test.insert({});
      > db.test.insert({});
      > db.test.insert({});
      > db.test.insert({});
      > db.test.insert({});
      > db.test.find({foo: {$exists: false}}).count();
      5
      > db.test.ensureIndex(

      {foo: 1}

      ,

      {sparse: true, safe: true}

      );
      > db.test.find({foo: {$exists: false}}).count();
      0
      > db.test.find({foo: {$exists: false}}).explain();
      {
      "cursor" : "BtreeCursor foo_1",
      "nscanned" : 0,
      "nscannedObjects" : 0,
      "n" : 0,
      "millis" : 0,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : false,
      "indexOnly" : false,
      "indexBounds" :

      { "foo" : [ [ null, null ] ] }

      }

        Attachments

          Issue Links

            Activity

              People

              Votes:
              12 Vote for this issue
              Watchers:
              15 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: