MongoDB 'connection timeout' During Debugging

191 views
Skip to first unread message

Chris Troutner

unread,
Oct 20, 2016, 3:00:55 PM10/20/16
to Keystone JS
Does anyone know how to increase the connection timeout setting for MongoDB?

While trying to debug my KeystoneJS application, I am frequently stopped by MongoDB 'connection timeout' errors. I've searched around a bit and can't figure out how to increase the timeout setting to avoid this message.

Chris Troutner

unread,
Oct 20, 2016, 3:43:43 PM10/20/16
to Keystone JS
Managed to answer my own question. The answer lies in the file node_modules/keystone/lib/core/openDatabaseConnection.js. I changed this part of the file:
 
} else {
  debug
('connecting to mongo');
  keystone
.initDatabaseConfig();
  keystone.mongoose.connect(keystone.get('mongo'), keystone.get('mongo options'));
}



So that it looks like this:

} else {
  debug
('connecting to mongo');
  keystone
.initDatabaseConfig();
  keystone
.mongoose.connect(keystone.get('mongo')+'?connectTimeoutMS=300000&socketTimeoutMS=300000', keystone.get('mongo options'));
}


This sets the timeout to 5 minutes. I'm not sure what it was before (probably 30 seconds from what I've read), but it fixed my problem with debugging. 

I hope this helps others!

-Chris Troutner
Reply all
Reply to author
Forward
0 new messages