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.
import User from './user.model';
// POST request for the creation of users
export function create(req, res) {
const users = req.body; // Array of users
// We can also try to use User.create(users), doesn't change the issue
return User.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?