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

Inclusion of "null" in "distinct" result depends on existence of index

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.6.8
    • Index Maintenance
    • None
    • ALL
    • Hide

      > db.test_col.find()
      { "_id" : ObjectId("54f6c5dbf79146d1fdfd0766"), "test_field" : "test_value_1" }
      { "_id" : ObjectId("54f6c5dff79146d1fdfd0767") }
      > db.test_col.distinct("test_field") 
      [ "test_value_1" ]      <------------------ Without index - "null" not included
      > db.test_col.createIndex({"test_field": 1})
      {
              "createdCollectionAutomatically" : false,
              "numIndexesBefore" : 1,
              "numIndexesAfter" : 2,
              "ok" : 1
      }
      > db.test_col.distinct("test_field")
      [ null, "test_value_1" ]  <------------------ With index - "null" included

      Show
      > db.test_col.find() { "_id" : ObjectId("54f6c5dbf79146d1fdfd0766"), "test_field" : "test_value_1" } { "_id" : ObjectId("54f6c5dff79146d1fdfd0767") } > db.test_col.distinct("test_field") [ "test_value_1" ] <------------------ Without index - "null" not included > db.test_col.createIndex({"test_field": 1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.test_col.distinct("test_field") [ null, "test_value_1" ] <------------------ With index - "null" included

    Description

      When calling distinct on a field which is missing from some of the records, the result either includes or does not include null, depending on whether there is an index in that field.

      Attachments

        Activity

          People

            Unassigned Unassigned
            yonmost Yonatan Most
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: