i'm a student of Nodejs. learning for few months. this is one of my practice project. but i'm stuck on an ERROR, that show me - "MongoError: E11000 duplicate key error collection cms_demo1.posts index: username_1 dup key: { : null }". i don't know what to do. pls help.
this is the schema i'm using.
var postSchema = new mongoose.Schema ({
title: String,
content: String,
image: String,
createdOn: {type: Date, default: Date.now},
});
postSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("post", postSchema);
and this is the post method.
app.post("/posts", function(req, res){
var title = req.body.title;
var content = req.body.content;
var image = req.body.image;
var newPost = {title: title, content: content, image: image};
post.create(newPost, function(err, npost){
if(err){
console.log(err);
} else {
res.redirect("/posts");
}
});
});