[SERVER-6471] aggregation $min uses Value ordering to compare null and undefined values, does not exclude null and undefined values from consideration Created: 16/Jul/12  Updated: 20/Mar/13  Resolved: 11/Dec/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 2.3.2

Type: Improvement Priority: Major - P3
Reporter: Aaron Staple Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-974 Document new aggregation $min behavio... Closed
is related to SERVER-6199 $first and $last accumulators accept ... Closed
Backwards Compatibility: Minor Change
Participants:

 Description   

Observed behavior: Undefined and null are considered less than other values and as a result the computed $min value of a field will be null or undefined if null or undefined values are present for that field.
Expected behavior: We should specify some rules for operators to handle null and undefined. Perhaps null and undefined values should be excluded when calculating the min value.

Test:

> c.drop()
true
> c.save( { a:1 } )
> c.save( { a:null } )
> c.aggregate( { $group:{ _id:0, max:{ $max:'$a' }, min:{ $min:'$a' } } } )
{
	"result" : [
		{
			"_id" : 0,
			"max" : 1,
			"min" : null  // min is computed as null, not 1
		}
	],
	"ok" : 1
}
> c.drop()
true
> c.save( { a:1 } )
> c.save( {} )
> c.aggregate( { $group:{ _id:0, max:{ $max:'$a' }, min:{ $min:'$a' } } } )
{ "result" : [ { "_id" : 0, "max" : 1 } ], "ok" : 1 } // min is 'undefined' so excluded from the result



 Comments   
Comment by Mathias Stearn [ 11/Dec/12 ]

$max would always prefer any existing value to any missing one. Results will change for $min with nullish values to prefer non-nullish ones.

Comment by auto [ 11/Dec/12 ]

Author:

{u'date': u'2012-12-05T23:55:25Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Normalize handling of Undefined vs EOO/missing in agg

Related tickets:
SERVER-6571 replace use of Undefined as missing with EOO
SERVER-6471 ignore nullish values in $min and $max accumulators
SERVER-6144 divide by zero makes field disappear (this solution isn't final)
Branch: master
https://github.com/mongodb/mongo/commit/459467c7cf47b57d8990eeb41c65b4e203e15b65

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