Mongo / node js如何查询对象数组。我们如何查询下面的ff数据。我想从与查询匹配的数据库中查询数据。我提供了以下所有数据,包括我的代码。谢谢。有任何想法吗 ?将不胜感激。谢谢
query { Year: { '$in': 2007 },
Make: { '$in': 'Honda' },
Model: { '$in': 'Piloto' },
Body: { '$in': 'Sport Utility' } }
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."
});
});
[
{
"_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
}
]
}
]
答案 0 :(得分:1)
我相信查询应如下所示:
PriceRule.find({
"data.year" : "2017",
"data.body" : "Sport Utility",
"data.model" : "Piloto",
"data.make" : "Honda",
});
记住,这只是演示如何实现它。