Combination of two docs from two different collection

Hi,
I have DB with 2 collections - collection A and collection B.
Doc-A from collection A
Doc-B1 and Doc-B2 from collection B.

Doc-A {x:[y1,y2,y3]
t: 10
}
Doc-B1 {name: y1
targets: [z1,z2]
}
Doc-B2 {name: y2
targets: [z3,z4]
}

How can I get the Doc-A’ (below) - I want all the other fields of doc-A will also be in Doc-A’ ?

Doc- A’ { x:[y1,y2],
t: 10
targets: [z1,z2,z3,z4]
}

I tried to unwind but I didn’t succeed to combine them after that into one document
thanks!

Please publish real JSON documents that we can cut-n-paste into our systems for us to experiment.

Also share what you have tried and indicate how it fails to produce the expected result. This will save us time by preventing us investigating in the wrong directory.

What field from Doc-A refers to Doc-B1? I suspect the y1, y2, y3 from Doc-A to match Doc-B1.name?

Have you tried the trivial $lookup from:B that uses localField:x and foreignField:name?

1 Like