使用mongoose的mongodb的连接超时 [英] Connection Timeout for mongodb using mongoose

查看:79
本文介绍了使用mongoose的mongodb的连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Node,express和MongoDB上的Web应用程序.我用猫鼬作为ODM.当我使用mongodb v3.0.1版测试我的应用程序时,它运行良好且未引发任何错误.但是,当我运行相同的代码v3.2.10时,一段时间后我得到了连接超时.

I have a web application running on Node, express and MongoDB. I use mongoose as the ODM. When i tested my application with mongodb version v3.0.1 it runs fine and throws no errors. But when i run the same code v3.2.10 i get a connection timeout after some time.

我收到以下错误消息:

Error: connection timeout at null.<anonymous> (/webapp/node_module/mongoose/lib/drivers/node-mongodb-native/connection.js:186:17)

我将mongoose.connect用于与本地mongodb实例的数据库连接. 连接方式有什么变化吗?

I use mongoose.connect for the db connection to the local mongodb instance. Has anything changed in the way of connection ?

推荐答案

我前一段时间有此问题.这完全取决于您使用的mongoosemongodb-core版本.现在,您必须指定以下参数:

I had this problem a while ago. It all depends on which version of mongoose and mongodb-core you are using. Right now, you have to specify the following parameters:

mongoose.connect("mongodb://user:password@address/db", {
  server: {
    socketOptions: {
      socketTimeoutMS: 0,
      connectionTimeout: 0
    }
  }
});

但是,就在昨天,正确的参数在哪里

However, just yesterday, the correct parameters where

mongoose.connect("mongodb://user:password@address/db", {
  server: {
    socketOptions: {
      socketTimeoutMS: 0,
      connectTimeoutMS: 0
    }
  }
});

我真的不知道该相信什么.

I don't really know what to believe in anymore..

这篇关于使用mongoose的mongodb的连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆