Calculations within aggregation pipeline inside Cloud code

Hi,

I have an aggregation pipeline like this:

{
      group: {
        objectId: '$project',
        depositPeriodSum: {
          $sum: '$depositPeriod',
        },
        borrowedAllTime: {
          $sum: '$loanValue',
        },
      },
    }

This pipeline works fine. DepositPeriodSum is pretty straightforward, but I would like to modify it a little. Instead of summing depositPeriod I would like to sum something like depositPeriod * (4 + zugModifier), where zugModifier is another column in database. Also zugModifier is sometimes undefined so I would also need to do something like (zugModifier || 0).

Is it possible to do calculations like that within the pipeline? I couldn’t find it anywhere in the docs.

that syntax is specific to mongo db, I don’t know if it is possible, but you can try to search in mongo db documentation

Oh, didn’t know that, great to know. Thanks a lot!