相关疑难解决方法(0)

与mongoDB的NodeJS连接错误

我有一个问题,我的socketIO应用程序(用nodeJS制作)与我的mongoDB连接.我尝试连接远程服务器,但它会引发我的错误

这是我的代码(mongoDB中没有设置用户/密码):

   var url = "mongodb://192.168.1.5:27017/DB"

   MongoClient.connect(url, function(err, db) {
           console.log("test")
           if (!err) {
                   console.log("test");
           }
           else {
                   console.dir(err)
           throw err
           }
   //  db.close();
   });
Run Code Online (Sandbox Code Playgroud)

这是当我启动服务器并尝试在导航器中启动应用程序时:服务器在端口80上侦听:

{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
/root/fys-realtime/examples/chat/node_modules/mongodb/lib/server.js:228
        process.nextTick(function() { throw err; })
                                            ^
Error
    at Error.MongoError (/root/fys-realtime/examples/chat/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:13:17)
    at Server.destroy (/root/fys-realtime/examples/chat/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:629:47)
    at Server.close (/root/fys-realtime/examples/chat/node_modules/mongodb/lib/server.js:344:17)
    at Db.close (/root/fys-realtime/examples/chat/node_modules/mongodb/lib/db.js:267:19)
    at /root/fys-realtime/examples/chat/node_modules/mongodb/lib/db.js:196:12
    at null.<anonymous> (/root/fys-realtime/examples/chat/node_modules/mongodb/lib/server.js:226:9)
    at g (events.js:180:16)
    at emit (events.js:98:17)
    at null.<anonymous> (/root/fys-realtime/examples/chat/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:238:68)
    at g (events.js:180:16)
Run Code Online (Sandbox Code Playgroud)

mongodb node.js socket.io

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

mongodb ×1

node.js ×1

socket.io ×1