我正在尝试在我的代码中执行2个find()查询,每个查询都在一个单独的mongo集合中。 'profiles'查询工作正常,但是当我添加'thresholds'查询时,一切都会中断,我的admin.storeSession永远不会被调用。知道这是什么问题吗?
var targetCollection = udb.collection('profiles');
var tc2 = udb.collection('thresholds');
targetCollection.ensureIndex({username: 1}, {unique : true}, function(err){ //set username to unique in 'profiles'
if (!err){
targetCollection.find({username: uname}).toArray(function(err, results) { //search for profile doc that matches username
if( err || !results.length) //no document found
console.error(err);
else {
if (bcrypt.compareSync(pw, results[0].password)){ //compare password to hashed bcrypt password in record
console.log("login success");
admin.storeSession(request, results, function(err){ //store the user's document in the session store
if (err)
console.error(err);
});
console.log('MARKER');
tc2.find({username: uname}).toArray(function(err, results) { //search for profile doc that matches username
if( err || !results.length) //no document found
console.log(err);
else {
console.log("Found threshold doc");
admin.storeThresholds(request, results, function(err){ //store the user's document in the session store
if (err)
console.error(err);
});
}
});
}
else
console.log('Password hash does not match in system.');
}
response.redirect('/dashboard');
udb.close();
});
}