Login function with no callback

Hello, please forgive me if this is the wrong place.
I have a login function that’s supposed to locate the user data in the db by their email, however this code is not working, after some research i was informed that mongoose removed callback support, which the function uses, and I find myself unable to figure out how to adapt the code.
Here’s what I had:

try {
UserSchema.findOne({ email: req.body.email }, (error, user) => {
console.log("User:", user)

I have tried to rewrite as:

const userFound = UserSchema.findOne(req.body.email)

however the response is a huge object with way too much info and none that I need, I can’t use userFound.name to find the name for example because that is not in the response I get.

Thank you for your time

This seems a similar question

1 Like