I do some filter with mongodb but it return all of the data in my array. But i only want to get the specific element from that array. I cant find it in the document.
db.sales.aggregate([
{
$project: {
items: {
$filter: {
input: "$items",
as: "item",
cond: { $gte: [ "$$item.price", 100 ] }
}
}
}
}
])
Run above command I will this is result
{
"_id" : 0,
"items" : [
{ "item_id" : 2, "quantity" : 1, "price" : 240 }
]
}
Question is I only want to get the price
{
"_id" : 0,
"items" : [
{ "price" : 240 }
]
}
or even
{
"price" : 240
}
How to do it?