Aggregation in aggregation


I don’t understand how to do a certain aggregation.

I want to compute a ratio, let’s say

R = A/B

I know how to compute A with an aggregation.
I know how to compute B with an aggregation.

How to be able to get R in one aggregation ( without creating a temp table with $out)?

Thank you

Hello @Jordan_Garzon

you can compute a ratio like this, $addFields will take your computed values for A and B, in this example I’ve simple passed fixed values.

   {$addFields: { A: 6 }}, 
   {$addFields: { B: 3 }}, 
   {$project: {
     A: 1, 
     B: 1, 
     R: { $divide: [ "$A", "$B" ] } }