I am getting stuck on a Mongoose function. The goal of the function is to:
- Store DB query in the query variable
- Return True IF there is a DB query matching my criteria. False, otherwise.
The code looks something like:
let query = function (query) {
  return new Promise((res, rej) => {
    res(UserModel.findOne({ username: toString(query) }));
  })
    .then((user) => {
      return user;
    })
    .catch((rej) => {
      console.log(rej);
    });
};
let result = await query(usernameToQuery);
if (result == null) {
  return true;
} else {
  return false;
}
No matter what I do, this code will never return after the query statement has been resolved. All it ever returns to the calling function is promise <pending>. How would I fix this?
 
    