I store documents like that:
const offer = {
_id: UUID("b0b7bb8b-374b-4957-9902-536939f510e0"),
name: "test name",
products: [
{ id: "1", name: "Product name 1" },
{ id: "2", name: "Product name 2" }] }
]
};
I need query to get only id of offer and id of product for given product id:
{ _id: UUID("b0b7bb8b-374b-4957-9902-536939f510e0"), id: "1" }
To achieve that I try with query:
db.offers.find({ "products.id": "1" }, { _id: 1, "products.id": 1 })
But result was:
{
_id: UUID("b0b7bb8b-374b-4957-9902-536939f510e0"),
products: [
{ id: "1", name: "Product name 1" },
{ id: "2", name: "Product name 2" }
]
}
How could I do that?