I had the same problem when connecting to a replica set over the network and quickly releasing a large number of queries in a database script initialization.
When connecting to the same mongodb instance on the same computer, this was good, but over the network with a minimum delay of 2-3 ms to the replica set, this would cause closed socket errors.
I also changed the save time on both computers to 120 in the registry. MongoDB 3.0.6 server is located on Windows Server 2012, the application computer is on Windows 10.
Then I tried and had no effect (restarted the mongod services in the replica set first)
Then I added the ?connectTimeoutMS=120000&socketTimeoutMS=120000 part to the query string, and I had success over the network with a set of replicas.
When I looked at the documentation for the parameters, I found that the default timeouts for one instance server are 30,000 ms, but for the default replica set, 0ms
in: http://mongodb.imtqy.com/node-mongodb-native/2.1/reference/connecting/connection-settings/
see replication level options
socketOptions.connectTimeoutMS {Number, default: 0} TCP Connection timeout setting. socketOptions.socketTimeoutMS {Number, default: 0} TCP Socket timeout setting.
This is the documentation for the node.js. driver I could not find mongoose docs information on timeouts for sockets and connections for only 6-7 other options. I am currently assuming that mongoose will pass parameters that you specify verbatim, and not a whitelist of only certain options. then you can specify timeouts in the options object instead of the connection string.
source share