https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
Whole document is written to the "inventory_docs" field. Is there any way to shrink or $project the document which is going to written to "inventory_docs"
db.orders.aggregate([{
$lookup: {
from: "inventory",
localField: "item",
foreignField: "sku",
as: "inventory_docs"
}
}])
What I am saying is, rather than this;
{
"_id": 1,
"item": "abc",
"price": 12,
"quantity": 2,
"inventory_docs": [
{ "_id": 1, "sku": "abc", description: "product 1", "instock": 120 }
]
}
I want to create it as;
{
"_id": 1,
"item": "abc",
"price": 12,
"quantity": 2,
"inventory_docs": [
{ "_id": 1, "instock": 120 }
]
}
How can I do it?