Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoose unique error is now a MongoServerError not MongoError #71

Open
MarioVillar opened this issue May 31, 2023 · 0 comments
Open

Mongoose unique error is now a MongoServerError not MongoError #71

MarioVillar opened this issue May 31, 2023 · 0 comments

Comments

@MarioVillar
Copy link

Hello,

From mongoose version 6 onwards, MongoError has been changed to MongoServerError. I think mongoose-beautiful-unique-validation plugin is not working for mongoose >= 6 version due to this change, as in the isUniqueError function just err.name === 'BulkWriteError' || err.name === 'MongoError' is checked.

I suggest adding MongoServerError to this condition. In case of any doubt, I leave the error log using mongoose 7.0.4:

MongoServerError: E11000 duplicate key error collection: followupusers index: email_1 dup key: { email: "[email protected]" } at node_modules\mongodb\lib\operations\insert.js:50:33 at node_modules\mongodb\lib\cmap\connection_pool.js:327:25 at node_modules\mongodb\lib\sdam\server.js:207:17 at handleOperationResult (node_modules\mongodb\lib\sdam\server.js:323:20) at Connection.onMessage (node_modules\mongodb\lib\cmap\connection.js:213:9) at MessageStream.<anonymous> (node_modules\mongodb\lib\cmap\connection.js:59:60) at MessageStream.emit (node:events:512:28) at processIncomingData (node_modules\mongodb\lib\cmap\message_stream.js:124:16) at MessageStream._write (node_modules\mongodb\lib\cmap\message_stream.js:33:9) at writeOrBuffer (node:internal/streams/writable:392:12) { index: 0, code: 11000, keyPattern: { email: 1 }, keyValue: { email: '[email protected]' }, [Symbol(errorLabels)]: Set(0) {} }

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant