Skip to content Skip to sidebar Skip to footer

Mongodb Findone () Not Return Value Nodejs

I try to do some email verification after a user subscribes to my API, but when I do user.FindOne(token), the user is found but I not able to get the value of the user in the datab

Solution 1:

findOne returns a promise, you need to wait for it resolve to read the values.

change your function into this:

module.exports = asyncfunction (req, res, next) {
  const headToken = req.header('token');
  const token = awaitToken.findOne({ token: headToken })
  ... 
}

Post a Comment for "Mongodb Findone () Not Return Value Nodejs"