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

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

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.8
    • Component/s: 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

      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.

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

              Created:
              Updated:
              Resolved: