Error: no open connections at Db._executeQueryCommand Node.js

空扰寡人 提交于 2019-12-11 11:10:03

问题


I have a node application used with express framework. This application runs smoothly. But suddenly, after some point of time, it starts to give error as

"Error: no open connections at Db._executeQueryCommand"

From the description of above error, I am just getting that, node application might not be able to make connection to Database.

But, in spite of getting this error, some of the pages, that are rendered by node application are able to run.

One thing I will like to add is, there's no certain page, in which am getting this error, I mean to say that, suppose first time, I get this error in "/foo" page, and not in "/foo1" and "/foo2".

But, suppose, when I randomly refresh pages, the page which loaded with error before, that is "/foo" might not give error, and pages loading successfully before,that is "/foo1" and "/foo2", might give error.

Number of concurrent users for node application might not be ever more, approximately, they would be around 450.

Details: 1. Node Version : v0.10.29 2. Express Version : 4.9.0 3. MongoDB Version : 2.4.10 4. OS Linux

I searched for many solutions, but did not find a strong cause or even solution for the same.

Any help will be greatly appreciated.


回答1:


Check this issue, it suggests to use {auto_reconnect: true} for mongodb connection.

Also you can try following

// Connect to mongodb
var connect = function () {
  var options = { server: { socketOptions: { keepAlive: 1 } } };
  mongoose.connect('mongodb://localhost/db1', options);
};

connect();

mongoose.connection.on('error', console.log);
mongoose.connection.on('disconnected', connect);


来源:https://stackoverflow.com/questions/29342904/error-no-open-connections-at-db-executequerycommand-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!