I have an orders table and a forms table. forms has many orders and i ran a successful $lookup with the following:
{
from: 'orders',
localField: 'slug',
foreignField: 'form_slug',
as: 'orders'
}
I then try to project like this:
{quantities : "$orders.line_items.quantity"}
The issue is that i get an array of nested arrays (see result below), when i really just want a sum total.
Is is possible to somehow $sum these values within the nested array?
"quantities": [
[
NumberLong(1)
],
[
NumberLong(1),
NumberLong(1)
],
[
NumberLong(1)
],
[
NumberLong(1)
],
[
NumberLong(1)
],
[
NumberLong(1),
NumberLong(1),
NumberLong(1)
],
[
NumberLong(1)
],
[
NumberLong(1)
]
]