this postAddComment fire on clicking on add comment button
exports.postAddComment=(req,res,next)=>{
let id=req.body.id;
const text=req.body.comment;
Post.findById(id)
.then(res=>{
console.log(res)
const comment=new Comment({
comment:text,
postId:new mongoose.Types.ObjectId(res._id),
userId:req.user
})
return comment.save()
}).then(result=>{
res.redirect('/add-comment/postId')
})
}
Actually i want to enable comments on posts and for that I have aa different model for the comments and I want to set Posts(another model) reference in this comments model I tried everything but always getting an error of CastError