0
votes

My model:

Email_Sender: {
        type: String,
        trim: true,
        required: true
    },
    Email_Receiver: {
        type: String,
        trim: true,
        required: true
    },
    Message: [{
        msg: {
            type: String,
            trim: true
        },
        Date: {
            type: String,
            trim: true
        },
        Email: {
            type: String,
            trim: true
        }
    }]
const get_save_chat_emais = new chat({
                    Email_Sender : s_email,
                    Email_Receiver: r_email,
                    Message: [{
                        msg : message,
                        Date : date,
                        Email : r_email
                    }]
                });

await get_save_chat_emais.save();

MongoError: E11000 duplicate key error collection: chat_database.chats index: Email_Sender_1 dup key: { Email_Sender: "[email protected]" }

  • I do not use unique: true but getting duplicate error on email*
2

2 Answers

0
votes

maybe you defined it as unique before, in that case you need to drop the indexes

> use chat_database
> db.chats.dropIndex('chats.Email_Sender_1')

See my already data

see also get error on compass

0
votes

Try to check for indexes:

db.collectionNameHere.getIndexes();
db.collectionNameHere.dropIndex('Email_Sender_1');
db.collectionNameHere.getIndexes();

If it won't work, try to drop your collection or database if it possible.