I've seen a lot of answers on how to sum properties of objects in arrays within the array, but I'm trying to sum individual properties on an object in an array across documents. For example, given this document structure:
{
"id": 1,
"stats": [
{
"number": 100,
"year": 2014
},
{
"number": 200,
"year": 2015
}
]
},
{
"id": 2,
"stats": [
{
"number": 50,
"year": 2014
},
{
"number": 75,
"year": 2015
}
]
}
The desired output would be:
{
"stats": [
{
"number": 150,
"year": 2014
},
{
"number": 275,
"year": 2015
}
}
I don't want to sum the number property of 2014 and 2015, I want to sum it across 2014 for both documents.