当我运行以下代码时,有时 MongoDB会错误地说Connection was destroyed by application
回调中是否可以立即db.close()
?
User.findOne({ username: username }, function (err, user) {
db.close();
if (err) {
console.log('local.js user findone err', err);
return done(err);
}
if (!user)
return done(null, false, { message: 'Incorrect username.' });
bcrypt.compare(password, user.password, function (err, res) {
if (err)
return done(err);
if (!res)
return done(null, false, { message: 'Incorrect password.' });
return done(null, user);
});
});
});