MongoDB – 有太多的连接w / node.js

我正在为我的应用程序使用node.js和MongoDB。 每当我使用本地主机,我没有问题,应用程序工作正常。 但是,在服务器上,数据库将我限制为50个连接。 这里是一个日志的例子:

Wed Jul 27 13:33:29 [initandlisten] waiting for connections on port 27017 Wed Jul 27 13:33:29 [websvr] web admin interface listening on port 28017 Wed Jul 27 13:34:50 [initandlisten] connection accepted from 127.0.0.1:42035 #1 Wed Jul 27 13:35:16 [initandlisten] connection accepted from 127.0.0.1:42181 #2 Wed Jul 27 13:35:16 [initandlisten] connection accepted from 127.0.0.1:42182 #3 Wed Jul 27 13:35:25 [initandlisten] connection accepted from 127.0.0.1:42249 #4 ... Wed Jul 27 13:36:09 [initandlisten] connection accepted from 127.0.0.1:42518 #50 Wed Jul 27 13:36:10 [initandlisten] connection accepted from 127.0.0.1:42524 #51 Wed Jul 27 13:36:10 [initandlisten] can't create new thread, closing connection 

我使用命令mongod --maxConns=5000启动进程。 有谁知道什么可能会导致此连接限制?

你能发布你用来连接的代码吗? 如果您在每个请求中连接到数据库,那么您将很快无法使用连接。 在大多数情况下,最好在请求之间共享数据库连接,例如通过连接应用程序启动。