Hi,
I would like your help!
table_1
_id
id_table_3
table_2
_id
id_table_1
– subquery - sum total tb_3_valor
table_3
_id
tb_3_valor
const collection = db.collection('table_2').aggregate([
{
$lookup: {
from: "table_1",
let: {
id_table_3: "$_id"
},
pipeline: [
{
$match: {
$expr: {
$eq: [
"$$id_table_3",
"$id_table_3"
]
}
}
},
{
$lookup: {
from: "table_3",
let: {
table_1_id: "$_id"
},
pipeline: [
{
$match: {
$expr: {
$eq: [
"$$table_1_id",
"$table_1_id"
]
}
}
},
as: "dot_resultado_01"
}
}
],
as: "orc_resultado_02"
},
},
{ "$group": {
"_id": { campo:"$_id", somar: "$orc_resultado_02.dot_resultado_01.tb_3_valor",}
}},
]).toArray();
I would like to remove these lines from the array
[],
[],
[]
result:
[
{
"_id": {
"campo": "5545454545454545",
"somar": [
[
{
"$numberDecimal": "555"
}
]
]
}
},
{
"_id": {
"campo": "54555454545454",
"somar": []
}
},
{
"_id": {
"campo": "887854545454",
"somar": [
[],
[
{
"$numberDecimal": "223.00"
}
],
[],
[],
[]
]
}
}
]