NodeJS 与 mongoDB 的连接错误 [英] NodeJS connection error with mongoDB
本文介绍了NodeJS 与 mongoDB 的连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将 socketIO 应用程序(用 nodeJS 制作)与 mongoDB 连接时遇到问题.我尝试在远程服务器上进行连接,但它引发了我的错误
I've got a problem to connect my socketIO application (made with nodeJS) with my mongoDB. I try to connect on an remote server, but its throws me error
这是我的代码(在 mongoDB 中没有设置用户/密码):
Here's my code (there's no user/password set in the 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 端口:
And here's when I launch the server and I tried to launch the app in a navigator : Server listening at port 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)
推荐答案
对于几个错误返回此错误,例如:
This error is returned for several errors like :
- 服务器没有运行
- 您需要对用户进行身份验证
- 此数据库不存在
- mongodb 端口不是默认端口
检查这个.通常,您的问题只是这些原因之一
Check this. Normaly your problem is just one of these causes
这篇关于NodeJS 与 mongoDB 的连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文