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

Distinct command with no predicate can miss results when distinct field is first key pattern element of partial index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.7
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • Quint Iteration 7

      Distinct commands with no query predicate are incorrectly able to use a partial index, if the distinct field is the first element of the index key pattern. As a result, these distinct commands can miss results.

      Reproduce as follows:

      > db.foo.drop()
      true
      > db.foo.insert({a: 1, b: 1})
      WriteResult({ "nInserted" : 1 })
      > db.foo.distinct("a")
      [ 1 ] // expected
      > db.foo.ensureIndex({a: 1}, {partialFilterExpression: {b: 2}})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.distinct("a")
      [ ] // unexpected
      

            Assignee:
            rassi J Rassi
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: