[SERVER-6144] Aggregation should error out on divide or mod by zero Created: 20/Jun/12  Updated: 31/May/17  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: Aaron Staple Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-29410 Enhance aggregation to handle handle ... Backlog
Operating System: ALL
Participants:

 Description   

Original Title: dividing by zero makes field disappear

ExpressionDivide returns Undefined on divide by zero, which causes the field to be dropped. Might be more appropriate to return +/- Infinity or NaN.

c = db.c;
c.drop();
 
c.save( { a:NumberLong(10) } );
printjson( c.aggregate( { $project:{ z:{ $divide:[ '$a', 0 ] } } } ) );

Observed behavior: A field is removed on attempt to set its value to the output of a division by zero.
Expected behavior: The field is set to an appropriate value ( see above ) rather than removed.

The same occurs when attempting to mod by zero:

c.save( { a:NumberLong(10) } );
printjson( c.aggregate( { $project:{ z:{ $mod:[ '$a', 0 ] } } } ) );



 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

Comment by Mathias Stearn [ 13/Dec/12 ]

In 2.4 dividing or moding by zero will cause the pipeline to error out.

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:10:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.