[DOCS-14742] Clarify null vs missing behavior in group _id Created: 17/Aug/21  Updated: 30/Oct/23  Resolved: 18/May/23

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Patrick Meredith Assignee: Backlog - Query Optimization
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 37 weeks, 6 days ago

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



 Comments   
Comment by Sarah Olson [ 18/May/23 ]

Closing this ticket as WON'T FIX because it is relatively old and it appears that we were unable to reach consensus on whether this is intended behavior for documentation or a bug for the engineering team to address. 

Please don't hesitate to reach out if you have concerns or would like to reopen this ticket. 

Comment by Ryan Chipman [ 19/Aug/21 ]

it is likely impossible that we can change this behavior since it is user facing

This assumes that this is intended behavior, and not a bug.

I'd be curious to understand why this is considered intended behavior that should be documented as opposed to a bug – at first glance, this looks like a bug to me.

Comment by Eric Sedor [ 17/Aug/21 ]

Agreed Patrick; I think this belongs in https://docs.mongodb.com/manual/reference/operator/aggregation/group/#considerations. I'm moving this to the DOCS project

Generated at Thu Feb 08 08:11:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.