I have Orders and Products being connected by a third collection with OrderID, ProductID, Quantity.
I want to get the result grouped something like this:
{
OrderID: 1,
products:[
name: productname1, quantity: 3
name: productname2, quantity: 1
]
},
{
OrderID: 2,
products:[
name: productname3, quantity: 10
name: productname5, quantity: 4
]
}
I have managed to $lookup and $project it down to displaying each coupling/reference on its own:
{
OrderID: 1,
name: productname1,
quantity: 3
},
{
OrderID: 1,
name: productname2,
quantity: 1
},
{
OrderID: 2
...
},
{
OrderID: 2
...
}
Is this to any use, or am i thinking wrong here? I basically tried $push into an object, but that doesn't really work.