将我的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(); });
这时我启动服务器,我试图在导航器中启动该应用程序:
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)
解决方法
此错误返回以下几个错误,如:
>服务器未运行
>你需要验证用户
>这个数据库不存在
> mongodb端口不是默认端口
检查一下Normaly你的问题只是这些原因之一