我在一个MERN项目中工作,我想通过内部的OBJECTID从对象数组内部获取数据.
My model view个
I want to fetch 100 and 101 through the 102
I had tried two types of methods from previous 100 solution but they didn't work for me
app.get('/stud/:id', (req, res) => {
ProjectSchema.find({"projectmembers._id":req.params._id}, (err, data) => {
if (err) return res.status(500).send(err);
res.status(200).send(data);
});
})
the second one is个
app.get('/stu/:id', (req, res) => {
ProjectSchema.aggregate([
{
$unwind:"$projectmembers"
},
{$match : {
"projectmembers._id" : req.params._id
}}
], (err, data) => {
if (err) return res.status(500).send(err);
res.status(200).send(data);
});
})
The output of both code is 100