Using sparse: true still getting MongoError: E11000 duplicate key error

后端 未结 1 1495
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 01:21

Schema (../models/add.js)

var addSchema = new Schema({
    name: {type: String, unique: true, sparse: true},
    phone: Number,
    email: String,
    countr         


        
1条回答
  •  一生所求
    2021-01-13 01:36

    You need to drop the old, non-sparse index in the shell so that Mongoose can recreate it with sparse: true the next time your app runs.

    > db.contacts.dropIndex('name_1')
    

    0 讨论(0)
提交回复
热议问题