How to use the Mongoose findOne method?

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.