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.
{ CastError: Cast to ObjectId failed for value " 5ae8264a3812d31e7ac0c7c2" at path "_id" for model "Blog"