W
W
WizardW2019-07-01 11:26:16
MongoDB
WizardW, 2019-07-01 11:26:16

Find a user by username OR email?

How to find a user by username or by email, so that when registering, you can understand if the username or email is taken?

await UserModel.find(
      { username: uBody.username },
      (err, user) => {
        if (err) {
          error = "smth wrong";
        }
        if (user.length != 0) {
          if (user[0].username === uBody.username) {
            error = "username taken";
          }
          if (user[0].email === uBody.email) {
            console.log(user[0].username);
            error = "email taken";
          }
        }
      }
    );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question