Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-14742

Clarify null vs missing behavior in group _id

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • Affects Version/s: None
    • Component/s: manual
    • Labels:
      None

      In some situations null and missing are considered equivalent for the group key, in other places they are considered as distinct. Since it is likely impossible that we can change this behavior since it is user facing, we should document it for clarity.

      ex:
      > db.col.find()
      { "_id" : ObjectId("611551d7a383be5dd4240f53"), "a" : 1 }
      {"_id" : ObjectId("611551dba383be5dd4240f54") }
      "_id" : ObjectId("611551e1a383be5dd4240f55"), "a" : null }
      
      null == missing 
      > db.col.aggregate({$group: {_id: '$a'}})
      {"_id" : null }
      {"_id" : 1 }
      
      null == missing 
      > db.col.aggregate({$group: {_id: {'a': '$a'}}})
      {"_id" : {"a": null }}
      {"_id" : {"a": 1}}
      
      null != missing
      > db.col.aggregate({$group: {_id: {'a': '$a', 'b': '$a'}}})
      {"_id" : { "a" : null, "b" : null } }
      {"_id" : { "a" : 1, "b" : 1 } }
      {"_id" : {  } }
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              47 weeks, 6 days ago