MongoDB貓鼬中的E 11000重復(fù)密鑰錯(cuò)誤索引以下是我的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');我就是這樣把它保存在數(shù)據(jù)庫(kù)里的-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集合,沒(méi)有這樣重復(fù)的條目存在,讓我知道我做錯(cuò)了什么?菲伊-req.body.email和req.body.password正在獲取值。我也查過(guò)這個(gè)帖子,但沒(méi)有幫助。堆棧鏈接如果我完全刪除了,它就會(huì)插入文檔,否則它會(huì)拋出錯(cuò)誤“重復(fù)”錯(cuò)誤,即使我在local.mail中有一個(gè)條目
3 回答

胡說(shuō)叔叔
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
? mongo use dbName;db.dropDatabase();exit
- 3 回答
- 0 關(guān)注
- 1060 瀏覽
添加回答
舉報(bào)
0/150
提交
取消