H.I
H.I

Reputation: 23

MongoError: connect ECONNREFUSED

Why do we get this error?

db:error Error: Cannot open store: MongoError: connect ECONNREFUSED 0.0.0.0:27017 

We are trying to connect Deployd w/ Heroku and keep getting this error. Any ideas on what to do? Thanks a lot!

// require deployd
var deployd = require('deployd');

// configure database etc.
var server = deployd({
  port: process.env.PORT || 5000,
  env: 'production',
  db: {
        host: '0.0.0.0',//my real host name
        port: 27017,
        name: 'app', //my real app name
        credentials: {
            username: process.env.MONGODB_USERNAME,
            password: process.env.MONGODB_PASSWORD
        }
      }
});

// heroku requires these settings for sockets to work
server.sockets.server.set('transports', ["xhr-polling"]);


// start the server
server.listen();

// debug
    server.on('listening', function() {
           console.log("Server is listening on port: " + process.env.PORT);
    });

// Deployd requires this
server.on('error', function(err) {
    console.error(err);
     process.nextTick(function() { 

        // Give the server a chance to return an error
           process.exit();
     });
});

Upvotes: 0

Views: 2597

Answers (1)

hunterloftis
hunterloftis

Reputation: 13799

The error ECONNREFUSED 0.0.0.0:27017 is telling you that your app is trying to connect to a service at 0.0.0.0 on port 27017, and that the service is refusing to connect.

0.0.0.0 is probably wrong. It means "all IP addresses on the local machine" when used in a listening context. It means "the default route to the Internet" in a connecting context. Neither makes sense for reaching a service.

Is this hardcoded into your app? Usually, you'll want to use environment variables to get things like service endpoints, and usually services will not exist on the same machine as your app.

Upvotes: 1

Related Questions