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

Sparse indexes should not be assigned to {$in: [null, ...]} predicates

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.5
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Minor Change
    • ALL
    • Quint Iteration 5

      Sparse indexes are incorrectly assigned to {$in: [null, ...]} predicates. As a consequence, {$in: [null, ...]} queries can omit documents from the result set that are missing the value of the given field, if a sparse index is assigned to the $in predicate.

      Reproduce as follows:

      > db.foo.drop()
      true
      > db.foo.ensureIndex({a: 1}, {sparse: true})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.insert({})
      WriteResult({ "nInserted" : 1 })
      > db.foo.find({a: {$in: [null]}}) // No results: unexpected.
      > db.foo.find({a: {$in: [null]}}).hint({$natural: 1}) // 1 result: expected.
      { "_id" : ObjectId("55477a258aa4f4cc73af71a5") }
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: