Validating an Existing Document in Mongo

I am new to Mongo and use Mongoose as ORM.

To register a user, I use email as unique. I want to check if the letter is really in use, and if not, do something (maybe save, maybe the next registration step, etc.).

Sorry for what seems like a simple question, but I did not find an answer for him.

If it is not upsert. This means that you are inserting a document, even if I'm not quite ready ...

+5
source share
1 answer

Are you asking how to find a document?

db.users.findOne({email => 'foo@example.com'})

If it returns something, the document exists. Otherwise, it is not.

+7
source

All Articles