We are using the C# driver (1.9.1) for Mongo DB. We have some fallback logic which needs to run if the DB is not accessible, however the default timeout is too long. We tried to change it but the values we put are getting ignored. For the tests we were using the IP of a non-responding machine.
We tried setting the timeout in the connection string:
<add key="Mongo" value="mongodb://xxx.xxx.xxx.xxx:27017/?socketTimeoutMS=2000&connectTimeoutMS=2000&waitqueuetimeoutms=2000"/>
Or via the code:
var client = new MongoClient(new MongoClientSettings
{
Server = new MongoServerAddress("xxx.xxx.xxx.xxx"),
SocketTimeout = new TimeSpan(0, 0, 0, 2),
WaitQueueTimeout = new TimeSpan(0, 0, 0, 2),
ConnectTimeout = new TimeSpan(0, 0, 0, 2)
});
Both time the requests timeout after an average of about 20 seconds.
What could be wrong in the way we are setting the timeout options.