Fix grouping over nonexisting keys by Ponewor · Pull Request #502 · mongomock/mongomock

There were two issues with $group stage.

  1. Whenever the _id field was a dictionary itself and one of its subfields was absent in a queried document, mongomock was instantly assuming the whole _id field value is None.
  2. The accumulations inside $group stage should take place even if accumulated expressions consist of non-existent fields. Instead, mongomock has been throwing an error.

It's my first time ever contributing and I'm not sure if I should have added corresponding issues using Issues panel in the first place. I hope everything is alright.

EDIT
I have added the $addFields aggregation stage and completely rewritten arithmetic operators - there were many problems with them, the most important changes are
-the unary operators now also accept single arguments given as [argument]
-$add operator supports date addition
-$subtract operator supports date and timedelta subtraction
-better handling of empty arrays and null values