Mongo/node js how to query an array of objects. How can we query the ff data below. I wanted to query data from the database where data matches with the query. I have provided all the data below including my code. thanks. any ideas ? would be much appreciated. thanks
query paramter
query { Year: { '$in': 2007 },
Make: { '$in': 'Honda' },
Model: { '$in': 'Piloto' },
Body: { '$in': 'Sport Utility' } }
query
PriceRule.find({ data : query })
.then(rules => {
console.log("Data Result :" , rules)
res.send(rules);
}).catch(err => {
res.status(500).send({
message: err.message || "Some error occurred while retrieving price rules."
});
});
Data in the database
[
{
"_id": "5de60cdbe5e5a52760d6aaf8",
"name": "ada",
"summer_sale_value": "1000",
"description": "dasdsa",
"__v": 0,
"data": [
{
"_id": "5de60cdbe5e5a52760d6aaf9",
"body": null,
"model": null,
"year": [
"2007"
],
"make": null
}
]
},
{
"_id": "5de611c30f0c2548c4d60f32",
"name": "23",
"summer_sale_value": null,
"description": "1212321",
"__v": 0,
"data": [
{
"_id": "5de611c30f0c2548c4d60f33",
"body": null,
"model": null,
"year": [
"2007"
],
"make": null
}
]
},
{
"_id": "5de61be7af76ca3efc82beec",
"name": "dasd",
"summer_sale_value": null,
"description": "sadsad",
"__v": 0,
"data": [
{
"_id": "5de61be7af76ca3efc82beed",
"body": null,
"model": null,
"year": [
"2009"
],
"make": null
}
]
}
]