0

In the server logs after a process has been successfully connected to mongo via node 6.11.1 and mongoose 4.10.4 I started seeing this error:

MongoError: failed to connect to server [aws-us-east-1-portal.8.dblayer.com:15180] on first connect [MongoError: connection 0 to aws-us-east-1-portal.8.dblayer.com:15180 timed out]

During this time, mongoose recognized an issue:

mongoose.connection.readyState had a value of 0.

What else can I do to debug the connection issue? Is there some other way I can inspect this or figure out what's going on and how to resolve it?

The mongo database (version 3.2.10) is actually running over at compose.io and during this time the compose.io interface is showing all healthy statuses for the database.

  • Node: 6.11.1
  • Mongoose 4.10.4
  • MongoDB: 3.2.10
dylanjha
  • 2,303
  • 4
  • 28
  • 47
  • use CLI command to connect mongoDB on server. `mongo [host]:[port] -u [user] -p [password]`. if connect success. the problem is cause by program otherwise by DB. – Neil Wong Jul 13 '17 at 03:22
  • @NeilWong the connection error is intermittent, sometimes it works, sometimes it has errors. The CLI works when I try it, most of the time (99%) the mongoose connection is healthy, but other times it is in this error state – dylanjha Jul 17 '17 at 22:47

1 Answers1

0

Can you try to increase timeout period like below:

const mongoose = require('mongoose');
const option = {
    socketTimeoutMS: 30000,
    keepAlive: true,
    reconnectTries: 30000
};

const mongoURI = process.env.MONGODB_URI;
mongoose.connect(mongoURI, option).then(function(){
    //connected successfully
}).catch(function(err) {
    //err handle
});
Brij
  • 6,086
  • 9
  • 41
  • 69