Categories
JavaScript Answers

How to use the Mongoose findOne method?

Spread the love

Sometimes, we want to use the Mongoose findOne method.

In this article, we’ll look at how to use the Mongoose findOne method.

How to use the Mongoose findOne method?

To use the Mongoose findOne method, we call it with an object with the values we’re looking for and a callback that has the returned results.

For instance, we write

Auth.findOne({
  name
}, (err, obj) => {
  console.log(obj);
});

to call findOne to find entries with the name field set to name.

Then we get the returned result from the obj parameter in the callback.

Conclusion

To use the Mongoose findOne method, we call it with an object with the values we’re looking for and a callback that has the returned results.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *