Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6144

Aggregation should error out on divide or mod by zero

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.2
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • ALL

      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 ] } } } ) );
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: