2015-08-15 182 views
-1

我的API在无法访问子对象的属性

http://52.24.34.186:3000/api/posts/

=========================== =============================

router.route('/users/root/:id').get(function(req, res) { 
    User.findOne() 
    .populate('countryId') 
    .populate('stateId') 
    .populate('districtId') 
    .populate('mandalId') 
    .populate('villageId') 
    exec({villageId._id: req.params.id}, function(err, userObj) { 
    if (err) { 
    return res.send(err); 
    } 
    res.json(userObj); 
}); 
}); 

==>显示错误为 “意外的标记”。

at“exec({villageId._id:req.params.id},function(err,userObj){”

请有人帮助我吗?

回答

2

您在exec(之前缺少.

此外,villageId._id是一个无效的属性名称。也许你打算只用{ villageId: req.params.id }

+0

感谢您的回答。即使在exec()之前保留点之后,我也遇到了同样的错误。 – Vasu

+0

你可能是对的。但我需要检查'req.params.id'与我的villageId._id没有_id。怎么做? – Vasu

+0

你是什么意思“检查'req.params.id'与我的villageId._id?” – mscdex