I'm trying to find if a Username exists within my account collection. One account can have multiple users, but I'm trying to check if the username exists before I create an object with that username and return it if it does.
For now, I'm focusing on simply checking if it does exist. This is what I currently have:
const acc = await Account.findOne({"Email": req.body.Email});
if(!acc) throw Error('Email not found');
if(Account.findOne({"Users.Username":req.body.User.Username})) throw Error('Username already exists');
Edit: Not sure if this will help, but it's throwing the error, even when the User array is empty
awaitfor the second query ?