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

The same distinct command, the result sometimes contains null and sometimes does not

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.8, 6.0.12
    • Component/s: None
    • Labels:
    • Query Execution
    • ALL

      version:6.0.12 4.2.8

      db.t1.insert({id:1})
      db.t1.insert({id:2})
      db.t1.insert({})
      db.t1.insert({id:2})

      db.t1.find()

      { “_id” : ObjectId(“65a62118842d8bddd7ef9699”), “id” : 1 }
      { “_id” : ObjectId(“65a62119842d8bddd7ef969a”), “id” : 2 }
      { “_id” : ObjectId(“65a6211c842d8bddd7ef969b”) }
      { “_id” : ObjectId(“65a6211f842d8bddd7ef969c”), “id” : 2 }
      

      — There are no nulls in the result set

      db.t1.distinct(‘id’)
      [ 1, 2 ]

      – After creating the index, there are nulls in the result set

      db.t1.createIndex(\{id:1})
      {
      “numIndexesBefore” : 1,
      “numIndexesAfter” : 2,
      “createdCollectionAutomatically” : false,
      “ok” : 1
      }
      

      db.t1.distinct(‘id’)
      [ null, 1, 2 ]

      After adding the index, null values appeared in the result set, causing the application processing logic to change. I would like to ask if this is a bug.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            chaigang@126.com 志刚 柴
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: