Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS connection error with 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

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();
   });

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)
like image 437
Jeflow Avatar asked Mar 27 '15 14:03

Jeflow


1 Answers

This error is returned for several errors like :

  • server is not running
  • you need to authenticate user
  • this database does not exists
  • the mongodb port is not the default port

Check this. Normaly your problem is just one of these causes

like image 59
throrin19 Avatar answered Sep 21 '22 11:09

throrin19