我的模型:
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重复键错误集合:chat_database.chats index:Email_Sender_1dup key:{Email_Sender:"abc@gmail.com"}
尝试检查索引:
db.collectionNameHere.getIndexes();
db.collectionNameHere.dropIndex('Email_Sender_1');
db.collectionNameHere.getIndexes();
如果它不起作用,请尽可能删除您的收藏或数据库。
也许您之前将其定义为唯一的,在这种情况下您需要删除索引
> use chat_database
> db.chats.dropIndex('chats.Email_Sender_1')
看到我已经有的数据
参见罗盘上的获取错误