{
"data": {
"category": "mobile",
"products": [
{
"title": "Redmi Note 10 Pro"
},
{
"title": "Redmi Note 100 Profile"
}
]
},
"user": {
"name": "username"
}
}
How to get only specific object. Mongodb
I just want object who have the category as "mobile"
and title as "Redmi Note 100 Profile"
Result expected:
{
"data": {
"category": "mobile",
"products":{
"title": "Redmi Note 100 Profile"
}
},
"user": {
"name": "username"
}
}
I just don't want this object
{
"title": "Redmi Note 10 Pro"
}
I'm using this to get
db.collection("products").aggregate([{
"$unwind": "$data"
},
{
"$match": {
"data.category": "mobile",
"data.products.title": "Redmi Note 100 Profile",
}
}])
.toArray();
But, it's give me 2 object ?
{
"data": {
"category": "mobile",
"products": [
{
"title": "Redmi Note 10 Pro"
},
{
"title": "Redmi Note 100 Profile"
}
]
},
"user": {
"name": "username"
}
}
How to do ?