Hello,
I have a aggreation very slow :
[
{
$project: {
_id: 0,
XXX: 1,
AAA: 1,
BBB: 1,
VVV: 1,
CCC: 1,
HHH: 1,
EEE: 1
}
},
{
$lookup: {
from: "COL2",
let: {
XXX: "$XXX",
AAA: "$AAA",
BBB: "$BBB",
VVV: "$VVV"
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: ["$XXX", "$$XXX"]
},
{
$eq: ["$AAA", "$$AAA"]
},
{
$eq: ["$BBB", "$$BBB"]
},
{
$eq: ["$VVV", "$$VVV"]
}
]
}
}
}
],
as: "HG"
}
},
{
$match: {
"HG": { $exists : true, $not : { $size: 0 } }
}
},
{
$unwind: {
path: "$HG"
}
},
{
$lookup: {
from: "COL3",
let: {
OOO: "$HG.OOO",
UUU: "$HG.UUU"
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: ["$OOO", "$$OOO"]
},
{
$eq: ["$UUU", "$$UUU"]
}
]
}
}
}
],
as: "HA"
}
},
{
$match: {
"HA": { $exists : true, $not : { $size: 0 } }
}
},
{
$unwind: {
path: "$HA"
}
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
"$$ROOT",
{
QQQ: "$HG.QQQ",
OOO: "$HG.OOO",
UUU: "$HG.UUU",
FFF: "$HA.FFF",
UUU: "$HA.UUU",
OOO: "$HA.OOO"
}
]
}
}
},
{
$project: {
XXX: 1,
AAA: 1,
BBB: 1,
CCC: 1,
FFF: 1,
HHH: 1,
EEE: 1,
QQQ: 1,
UUU: 1,
OOO: 1
}
},
{
$out: "temp_col"
}
]
Some can say me what’s wrong with my query ?
Many thanks