-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Environment:
*Location*: http://docs.mongodb.org/manual/reference/operator/aggregation/mod/#exp._S_mod
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11
*Referrer*: http://docs.mongodb.org/manual/meta/aggregation-quick-reference/
*Screen Resolution*: 1440 x 900
*repo*: docs
*source*: reference/operator/aggregation/mod
*Location*: http://docs.mongodb.org/manual/reference/operator/aggregation/mod/#exp._S_mod *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11 *Referrer*: http://docs.mongodb.org/manual/meta/aggregation-quick-reference/ *Screen Resolution*: 1440 x 900 *repo*: docs *source*: reference/operator/aggregation/mod
-
-
3
The $mod function doesn't describe how it behaves for negative numbers.
What's -1 % 10, for example? Programming languages are generally split on how to answer this question. Python and Ruby say 9, while Java and C say -1. A nonnegative result is arguably more (mathematically) correct, but MongoDB generally follows Javascript, so maybe it gives -1 here?
Whichever one MongoDB does today, I can figure out by trial-and-error, but since it's not documented, is it guaranteed to be stable?
[AB: Seems like it would be a good idea to update the query operator $mod page also.]
Please see the $mod (eval query operator) vs $mod (aggregation) Behavior Report for background information, testing information, and pertinent questions.