Answer the question
In order to leave comments, you need to log in
Why does it give an error E11000 duplicate key error collection: app.profiles index: name_1 dup key?
const scheme = new Schema({
userId: { type: Types.ObjectId, unique: true },
name: {
type: String,
default: ''
},
lastName: {
type: String,
default: '',
},
middleName: {
type: String,
default: ''
},
login: {
type: String,
default: '',
},
email: {
type: String,
default: '',
},
group: {
type: String,
default: ''
},
active: {
type: Boolean,
default: false
},
position: {
type: String,
default: ''
},
education: {
type: String,
default: ''
}
});
mongoose.connect(config.mongoose.url, config.mongoose.options)
const profile = new Profile(data)
await profile.save()
await mongoose.disconnect()
unique = false
Answer the question
In order to leave comments, you need to log in
Miracles don't happen. The error clearly indicates a duplicate value for the name field.
Perhaps you did not set unique for this field, then someone else did it. )
An easy way to drop a table. If it does not work after that, then you need to look for the code that sets unique for name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question