MongoDB猫鼬中的E 11000重复密钥错误索引
useruser.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 }"}req.body.emailreq.body.password
慕雪6442864
胡说叔叔
随时随地看视频慕课网APP