dimanche 6 mai 2018

Can't update ID in mongo db , rest of the fields are working fine

var blogSchema = new mongoose.Schema({
title: String,
image: String,
body: String,
created: {type: Date, default: Date.now}

});

app.put("/blogs/:id",function(req,res){
Blog.findByIdAndUpdate(req.params.id, req.body.blog ,function(err,updateBlog){
    if(err){
        console.log(err);
        console.log(req.body.blog._id);
        console.log(req.body.blog.title);
        console.log(req.body.blog.image);
        console.log(req.body.blog.body);
    }
    else{
        res.redirect("/blogs/" + req.params.id);
    }
});

I have skipped the unnecessary code. The error I received as been pasted below. Just need help to figure out why my blog._id isn't working properly, the rest title,image,body are working properly.Console.log is printing blog._id as undefined. Any help will be appreciated. Thanks

Output error image

Aucun commentaire:

Enregistrer un commentaire