It is not directly accessible, but you can do this using the $cond and $subtract statements inside the $project , like this (as a JavaScript object):
{ $project: { amount: { $cond: [ { $lt: ['$amount', 0] }, { $subtract: [0, '$amount'] }, '$amount' ] }}}
So, if amount < 0 , then 0 - amount , otherwise amount used directly.
UPDATE
As with the 3.2 release of MongoDB, you can use the new expression operator of the expression $abs . it is straight:
{ $project: { amount: { $abs: '$amount' } }
Johnnyhk
source share