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

Clarify null vs missing behavior in group _id

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • None
    • manual
    • None

    Description

      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" : {  } }
      

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

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