loading...

MongoDB Tip - Querying For Single Document

victoromondi1997 profile image VICTOR OMONDI ・1 min read

If you're querying for a single document, prefer findOne over find

Usecase:

To find a user by an email field

One possible approach:

User.find({email: 'shubworkmail@gmail.com'});

Better Approach:

User.findOne({email: 'shubworkmail@gmail.com'});

Discussion

pic
Editor guide