DEV Community

VICTOR OMONDI
VICTOR OMONDI

Posted on

MongoDB Tip - Querying For Single Document

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'});
Enter fullscreen mode Exit fullscreen mode

Better Approach:

User.findOne({email: 'shubworkmail@gmail.com'});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)