亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

MongoDB貓鼬中的E 11000重復密鑰錯誤索引

MongoDB貓鼬中的E 11000重復密鑰錯誤索引

慕雪6442864 2019-07-10 15:29:10
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個贊

如果您仍然在您的開發環境中,我將刪除整個db并重新開始您的新模式。

從命令行

? mongo
use dbName;db.dropDatabase();exit


查看完整回答
反對 回復 2019-07-10
  • 3 回答
  • 0 關注
  • 1054 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號