S
S
Sood212020-09-12 10:07:25
Node.js
Sood21, 2020-09-12 10:07:25

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: ''
    }
});


When trying to save data
mongoose.connect(config.mongoose.url, config.mongoose.options)
    const profile = new Profile(data)
    await profile.save()
    await mongoose.disconnect()


Gives an error
MongoError: E11000 duplicate key error collection: app.profiles index: name_1 dup key: { name: "Dmitry" }
I assume that the error points to a duplicate value for the name field, but I do not set unique for this field, and even if Trying to install the error still works, tell me where else can I look? unique = false

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Cheremkhin, 2020-09-12
@Sood21

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 question

Ask a Question

731 491 924 answers to any question