无法连接到Mongo Server

时间:2012-06-22 06:03:21

标签: node.js mongodb

在该ip:port上没有mongo服务器或任何服务器或任何服务,但我们仍然遇到这种错误。

(lockerdb) Database connection error: { [Error: failed to connect to [127.0.0.1:10004]]
  [stack]: [Getter/Setter],
  [message]: 'failed to connect to [127.0.0.1:10004]',
  [arguments]: undefined,
  [type]: undefined }


node.js:201

        throw e; // process.nextTick error, or 'error' event on first tick






        ^

TypeError: Cannot call method 'close' of null
    at /home/<user>/Documents/Server_v1/ssc/ssc-lac/lac-util.js:1653:15
    at /home/<user>/node_modules/mongodb/lib/mongodb/db.js:247:16
    at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/server.js:383:7)
    at [object Object].emit (events.js:88:20)
    at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:93:15)
    at [object Object].emit (events.js:70:17)
    at Socket.<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection.js:385:10)
    at Socket.emit (events.js:67:17)
    at Array.0 (net.js:319:25)
    at EventEmitter._tickCallback (node.js:192:41)

导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:0)

您很可能仍在尝试连接该端口上的服务。

默认行为是尝试连接,当它无法连接时,它会因为您看到的错误而死亡。这是出于安全原因,因为连接错误90%的时间意味着崩溃的数据库(就像你的情况一样),这是不好的,不应该被忽略。

克服此错误的最简单方法是try catch连接块,以便了解何时收到连接错误并对其执行某些操作。