Here is the code snippet I am currently working with:
if (checkUserExists(serverID, userID) === null) {
console.log("was null");
addNewUserToDB(serverID, userID, username);
}
I am aiming for it to run only if mongoDB cannot find a match for both Server and UID. To achieve this, I have implemented the following function:
function checkUserExists(serverID, userID) {
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});
playerModel.findOne({"serverID": serverID, "userID": userID }, (err, player) => {
if (err) {
console.log(err);
} else {
console.log(player);
return player;
}
});
}
If a user is found, it will return the user object. If not, it will return null. However, the if statement never seems to trigger.