1

我有一个应该永远运行的 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)
4

1 回答 1

0

检查 MongoDB 的日志文件,看看它是否遇到任何导致连接中断的问题。正如您所提到的,如果日志中没有任何内容,重新启动 MongoDB 将是一件好事。

于 2012-12-18T14:11:45.290 回答