on-internet
← Community

MongoDB Aggregation - Sum value of nested arrays

Stack Overflow ·

I'm trying to get the sum of a specific field that's inside an array. The problem is, that array is also inside another array. My documents are as follow (simplified): { "nome": "test-1" "notas": [{ "numero_fiscal": "0001", "valores": { "portal": 1000, "arquivo": 1000 }, "abatimentos": [{ "valor": 250, "tipo": "TIPO 1" }, { "valor": 250, "tipo": "TIPO 2" }] }, { "numero_fiscal": "0002", "valores": { "portal": 2000, "arquivo": 2000 }, "abatimentos": [{ "valor": 500, "tipo": "TIPO 1" }, { "valor": 500, "tipo": "TIPO 2" }] }] } I want my output to be something like: { "_id": "resumo", "total_nota

Comments

Sign in or sign up to comment and upvote.

No comments yet.