Sum in each floor by category in aggregation

Thanks for the documents and the extra explication.

That is very interesting and I do not have an obvious solution at hand.

A possible solution to investigate is:

1 - $match the user
2 - $sort on date
3 - $group _id:null, with $push
4 - $set with a $reduce to create an array of each leg (the hard part)
5 - $set with a $reduce on the legs array that $sum the values

1 Like