我想从mongoDB用户中删除一个subdoc。然而,覆盖删除功能的猫鼬文档似乎光,正因为如此,我的函数返回以下错误:删除明快和猫鼬的subdoc
TypeError: Cannot read property 'id' of undefined
什么错在这段代码?我如何使subdoc id可访问,以便函数可以删除它?
// Remove a destination from the user
router.get('/delete', function(req, res, next) {
var subdoc = User.destinations.id(_id).remove()
user.save(function (err) {
if (err) return handleError (err)
})
})
玉模板
each dest in user.destinations
.destination
li= dest.airport
li= dest.daysAway
li= dest.day
li= dest.month
a(href='/delete') Delete this entry
分享您的架构或响应 – Sam