I am experiencing an issue with my login system connected to a MongoDB database - the result is always 0 even when searching for a record I know exists.
thePass = passWord.value
theUser = userName.value
loginButton.onclick = function() {
console.log(theUser)
socket.emit('login', {username: theUser, password: thePass})
}
const mongojs = require("mongojs")
const db = mongojs('localhost:27017/shadowRiseDB', ['player'])
var correctDetails = function(data, cb) {
db.player.find({username: data.username, password: data.password}, function(err, res) {
console.log(res.length)
if(res.length > 0)
cb(true);
else
cb(false);
});
}
socket.on('login', function(data) {
theDetails = data;
correctDetails(theDetails, function(res){
if(res) {
socket.emit('loginDetails',{success:true});
} else {
socket.emit('loginDetails', {success:false});
}
})
})
Despite my efforts, the if statement doesn't trigger as 'res' always returns 0 when trying to search for something in my database. What could be causing this issue?