我有一个登录系统连接到mongodatabase,但结果总是0,即使我正在搜索我知道的记录。
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});
}
})
})if语句不会触发,因为在我的db中查找某些内容时,res总是为0。发生什么事了?
发布于 2020-08-14 18:08:36
在检查长度之前,尝试将res转换为数组:
if(res.toArray().length>0){
...
}https://stackoverflow.com/questions/59023768
复制相似问题