1. 程式人生 > >MongoDB connection timeout

MongoDB connection timeout

http://stackoverflow.com/a/39603895/2177408

Error: 

{[MongoError: connection 39 to 127.0.0.1:27017 timed out]
  name:'MongoError',
  message:'connection 39 to 127.0.0.1:27017 timed out'}

Solution:

var options ={ 
  server:{ 
    socketOptions:{ 
      keepAlive:300000, connectTimeoutMS:30000}}, 
  replset:{ 
    socketOptions
:{ keepAlive:300000, connectTimeoutMS :30000}}};

Then put it in here:

if(process.env.MONGODB_URI){
  mongoose.connect(process.env.MONGODB_URI, options);}else{// Connect to local database}