how do i get the total sum sum of an array from a nested field?

Use the following snippet below:

const result = Users.aggregate([
{
   $match: {
     //Your find block here
   }
},
{
    $unwind: "$history"
},
{
    $project: {
        totalTimeHistory: { $sum: "$history.time"}
    }
}
])

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top