Node Js - 如果连接断开,猫鼬查找不会抛出错误

Nodejs - Moongose find doesn't throw error if connection broken

我正在使用以下连接到我的 mongodb。我在密码上打错了,身份验证失败了,但直到我进行了模型搜索我才意识到,而不是发现错误,它只是挂起。

如果没有打开的连接,模型不应该抛出错误而不是挂起吗?

mongoose.connect(uristring, function (err, res) {
  if (err) {
  console.log ('ERROR connecting to: ' + uristring + '. ' + err);
  } else {
  console.log ('Succeeded connected to: ' + uristring);
  }
});

User.findOne({
    'valid.email': Email
  }, function(err, user) {
    if (err) {
      callback({  this is never called });
    }

尝试使用 disconnected 事件处理程序。

disconnected: Emitted after getting disconnected from the db.

conn.on('disconnected', callback);