This is my equipment
schema inside my model-
var mongoose = require("mongoose");
var passportLocalMongoose = require("passport-local-mongoose");
var equipmentSchema = new mongoose.Schema({
name :String,
amount :Number,
category :String,
});
//adds some methods from the 'PLM' package to our equipmentSchema
equipmentSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("Equipment", equipmentSchema);
To post data into the DB;
var Equipment = require("./models/equipment")
//handling equipment details
app.post("/Dashboard/equipments", function(req,res){
Equipment.create(new Equipment({name:req.body.name, amount:req.body.amount, category: req.body.category}),function(err, equipment){
if(err){
console.log(err);
return res.render("Dashboard/equipments");
}
});
});
I get this error
message: 'E11000 duplicate key error collection: Fitness.equipment index: username_1 dup key: { : null }', driver: true, index: 0,
code: 11000,
In my table, there's no 'Username' field and no duplicate records too.I can save only one record to the DB and if i try again, i get the duplicate error above. What i'm i doing wrong?