I am working with a node.js and mongoDB application with a simple user registration. Its important that an email address is unique.
Any opinion on how to verify uniqueness? I am thinking of 2 ways.
Any thoughts?
Second way is much better!
You will produce many many race conditions if you use 1 approach
For example if you add same email in two request. And both have checked (before someone add). There will be created two documents with same email.
Also if you are not able to have always email in document, but want to use unique constraint, you can use sparse index.