I have the following code;
if (checkUserExists(serverID, userID) === null) {
console.log("was null");
addNewUserToDB(serverID, userID, username);
}
I want it to execute if mongoDB doesn't find a match for the Server & UID. Therefore, I have this;
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 there's a found user, it returns the user object. If there isn't, it returns the object, which will be null. However, the if statement never triggers.