[SERVER-7932] Change handling of nullish values in math expressions Created: 13/Dec/12  Updated: 28/Oct/15  Resolved: 17/Dec/12

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

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Major Change
Operating System: ALL
Participants:

 Description   

Currently when a nullish (missing/EOO, Undefined, or Null) value is used in a math expression such as $add, we treat it as 0. I think a better behavior would be to make the output always be NULL if any input value is nullish. If users want the old behavior, they can use $ifNull:

{$mulitply: [10, '$value']} -> {$multiply:[10, {$ifNull:['$value', 0]}]}

Note: this change only applies to the expressions $add, $multiply, $subtract, etc. The $group accumulators ($min, $max, $sum, and $avg) will continue to ignore nullish values.



 Comments   
Comment by auto [ 15/Dec/12 ]

Author:

{u'date': u'2012-12-14T21:02:41Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Improve aggregation handling of nullish Values - part 2

Changes:

  • Nullish values in math expressions (but not accumulators) result in NULL.
  • $divide or $mod by 0 now uasserts.
  • uassert in math expressions if inputs are neither nullish nor numeric.
  • $group fills missing accumulators with NULL rather than Undefined.

Related Tickets:
SERVER-7932 Fix handling of nullish Values in math expressions
SERVER-6144 $divide by 0 makes field disappear
Branch: master
https://github.com/mongodb/mongo/commit/69ceee8d9c8008b974f11937941e7a591124b82c

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