我有一个应该永远运行的Node.js应用程序并且正在创建一个mongodb连接。但是,几秒钟后连接会继续关闭并导致应用程序崩溃。我已经将所有代码都删除回了create connection方法。应用代码:
var mongoose = require('mongoose'),
db = mongoose.createConnection("mongodb://localhost:28017/mwa");
然后几秒钟后我得到:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connection closed
at [object Object].<anonymous> (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:557:24)
at [object Object].emit (events.js:88:20)
at [object Object].<anonymous> (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:109:15)
at [object Object].emit (events.js:70:17)
at Socket.<anonymous> (/home/gavin/mwa/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:427:12)
at Socket.emit (events.js:67:17)
at Array.0 (net.js:335:10)
at EventEmitter._tickCallback (node.js:192:40)
答案 0 :(得分:0)
检查MongoDB的日志文件,查看是否有任何问题导致其终止连接。正如您所提到的,如果日志中没有任何内容,重新启动MongoDB将是一件好事。