E11000 duplicate key error index in mongodb mongoose

前端 未结 25 2003
自闭症患者
自闭症患者 2020-11-22 05:49

Following is my user schema in user.js model -

var userSchema = new mongoose.Schema({
    local: {
        name: { type: String },
         


        
25条回答
  •  忘了有多久
    2020-11-22 06:18

    I got this same issue when I had the following configuration in my config/models.js

    module.exports.models = {
      connection: 'mongodb',
      migrate: 'alter'
    }
    

    Changing migrate from 'alter' to 'safe' fixed it for me.

    module.exports.models = {
      connection: 'mongodb',
      migrate: 'safe'
    }
    

提交回复
热议问题