You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really like this plugin and it's working really good. Unfortunately currently I'm facing on this issue regarding duplicate keys error which it's blocking my app development somehow.
importUserfrom'./user.model';// POST request for the creation of usersexportfunctioncreate(req,res){constusers=req.body;// Array of users// We can also try to use User.create(users), doesn't change the issuereturnUser.insertMany(users).then(respondWithResult(res,201)).catch(handleError(res));}
I really like this plugin and it's working really good. Unfortunately currently I'm facing on this issue regarding duplicate keys error which it's blocking my app development somehow.
Info
Let's suppose to have this scenario:
Users array that I want to save into MongoDB
Current users saved in MongoDB
user.model.js
user.controller.js
I got the following error:
E11000 duplicate key error collection: mydb.users index: username_1 dup key { : "tran"}
.In this case both insertions fails.
If I dont't have any user saved in the db with username "tran", the first insertion goes fine, but the second one throws the same error.
This issue was already mentioned here and seems really similar to mine, why wasn't taken in consideration with a proper solution until now?
The text was updated successfully, but these errors were encountered: