我有一个应该永远运行的 Node.js 应用程序,并且正在创建一个 mongodb 连接。然而,连接在几秒钟后继续关闭并使应用程序崩溃。我已将所有代码剥离为仅创建连接方法。应用代码:
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)