As the Waterline's unique
attribute is ignored for MongoDB, I take up the decision to make a check for existing model entry in my code:
var username = req.param('username');
var email = req.param('email');
var asd = "";
// Do check if user already exists
User.findOne({username: username}, function (err, user) {
asd = "invalid USERNAME";
console.log(asd);
if(err){
return res.serverError('error creating user' + err);
}
if(user){
asd = "invalid USERNAME";
console.log(asd);
return res.json({status: "INVALID_USERNAME"});
}
});
User.findOne({email: email}, function (err, user) {
asd = "invalid EMAIL";
console.log(asd);
if(err){
return res.serverError('error creating user' + err);
}
if(user){
asd = "invalid EMAIL";
console.log(asd);
res.json({status: "INVALID_EMAIL"});
}
});
// Create the user
User.create({.....});
Nevertheless, I never get in the findOne
methods, even though the user with the provided credentials does exist in the database. I tried debugging, and I don't get in the statement. I even put this asd
variable, just to check if smth happens, but unsuccessfully. And the user keeps being created again and again, with the same credentials.
Any thoughts on what am I missing?