MongoDB貓鼬中的E 11000重復密鑰錯誤索引以下是我的user模式user.js模型-var userSchema = new mongoose.Schema({
local: {
name: { type: String },
email : { type: String, require: true, unique: true },
password: { type: String, require:true },
},
facebook: {
id : { type: String },
token : { type: String },
email : { type: String },
name : { type: String }
}});var User = mongoose.model('User',userSchema);module.exports = User;我就是這樣在我的控制器里用它的-var user = require('./../models/user.js');我就是這樣把它保存在數據庫里的-user({'local.email' : req.body.email, 'local.password' : req.body.password}).save(function(err, result){
if(err)
res.send(err);
else {
console.log(result);
req.session.user = result;
res.send({"code":200,"message":"Record inserted successfully"});
}});誤差 -{"name":"MongoError","code":11000,"err":"insertDocument :: caused by :: 11000 E11000 duplicate key error index: mydb.users.$email_1
dup key: { : null }"}我檢查了db集合,沒有這樣重復的條目存在,讓我知道我做錯了什么?菲伊-req.body.email和req.body.password正在獲取值。我也查過這個帖子,但沒有幫助。堆棧鏈接如果我完全刪除了,它就會插入文檔,否則它會拋出錯誤“重復”錯誤,即使我在local.mail中有一個條目
3 回答

胡說叔叔
TA貢獻1804條經驗 獲得超8個贊
? mongo use dbName;db.dropDatabase();exit
- 3 回答
- 0 關注
- 1054 瀏覽
添加回答
舉報
0/150
提交
取消