My collection data is like this :
{
"_id" : ObjectId("590ad1f747627f86e585a4af"),
"code" : "NL",
"name" : "Holand",
"background" : "https://vfbdt"
"topics" : [
{
"name" : "overview",
"facts" : [
{
"key" : "capital",
"value" : "Kuala Lumpur"
},
{
"key" : "population",
"value" : "232424234"
},
{
"key" : "reliogion",
"value" : "Islam"
}
]
},
{
"name" : "Good to know",
"facts" : [
{
"key" : "key1",
"value" : "value1"
}
]
}
]
}
I want to return all the facts by filter on name Topic name and code. I write this piece of code but it doesn't work correctly and return all collection just filter by code and does not consider topic.name
export function getFactsByCodeAndName(req, res, next) {
Country.find({code:req.params.code,'topics.name':req.params.name})
.exec((err, facts) => {
if (err) return next(err);
return res.status(200).json({
success: true,
message: 'Get country',
data: facts,
});
});
}
via Mehr
No comments:
Post a Comment