Monday 1 May 2017

TypeError: Cannot read property '_doc' of undefined when post the new data

guys. I am doing the course about the Nodejs and express. I created where the users enter the reviews about the dish. Now below is part of the code from my application:

.post(function (req, res, next) {
Dishes.findById(req.params.dishId, function (err, dish) {
    if (err) throw err;
    req.body.postedBy = req.decoded._doc._id;
    dish.comments.push(req.body);
    dish.save(function (err, dish) {
        if (err) throw err;
        console.log('Updated Comments!');
        res.json(dish);
    });
});

})

Now when I enter a new comment to the dish, I got an error that:

TypeError: Cannot read property '_doc' of undefined

Can someone help me to solve this problem.



via Agil Yolchuyev

No comments:

Post a Comment