I keep getting the error message
ValidatorError: Path `title` is required
and my data is not getting stored in the database.
What could be causing this issue?
const mongoose=require('mongoose');
const Articleschema= new mongoose.Schema({
title:{
type:String,
required:true
},
category:{
type:String
},
content:{
type:String
},
postDate:{
type:Date,
default:Date.now()
}
});
var Article=module.exports=mongoose.model('Article',Articleschema);
router.post('/articles/create',(req,res)=>{
var article=new Article({
title:req.body.title,
})
article.save(function (err,data){
if (err) {
console.log(err)
}
console.log(data);
req.flash('success-message','Article successfully created')
res.redirect('/admin/articles')
})
})