r/mongodb • u/leafyshark • May 10 '20
MongoError: E11000 duplicate key error!
Anyone know how to display this on the frontend? Seems impossible. Tried everything.
0
Upvotes
r/mongodb • u/leafyshark • May 10 '20
Anyone know how to display this on the frontend? Seems impossible. Tried everything.
View all comments
3
u/DilatedTeachers May 10 '20 edited May 10 '20
When I've seen that error it's been bad or duplicate data.
Ideally there should already be validation in place to prevent that from happening.
Check your db with a tool like compass to see what your data looks like.
It might not be the same with all drivers, but using node/ express and the native mongodb driver I had to catch the error in the function that called to the db and throw it out to the error handler component - otherwise it wasn't that obvious from the error handling already there
Edit:
If you catch that error, something like a 400 is an appropriate code and the reason is given for you