Můžete to vyřešit pomocí $lookup
operátor. Zvažte následující agregační kanál:
// Execute aggregate, notice the pipeline is expressed as an Array
collection.aggregate([
{
"$lookup": {
"from": "product",
"localField": "content.product.$id",
"foreignField": "_id",
"as": "products"
}
},
{
"$lookup": {
"from": "clients",
"localField": "content.client.$id",
"foreignField": "_id",
"as": "clients"
}
},
], function(err, result) {
console.log(result);
});