这是我的模型中的equipment
模式-
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);
将数据发布到数据库中
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");
}
});
});
我收到此 错误
消息:'E11000重复键错误集合:Fitness.equipment 索引:username_1 dup键:{:null}',驱动程序:true,索引:0,
代码:11000,
在我的表中,没有``用户名''字段,也没有重复的记录。我只能将一个记录保存到数据库中,如果我再试一次,则会收到上面的重复错误。我在做什么错了?