The nodejs driver default
serverSelectionTimeoutMS is 30s. But for some scenarios, like inside AWS Lambda, waiting 30s is not ideal.
According to this documentation we should set it to 15s:
Lower the serverSelectionTimeoutMS to
15000from the default of
30000. MongoDB elections typically take 10 seconds, but can be as fast as 5 seconds on Atlas. Setting this value to 15 seconds (
15000milliseconds) covers the upper bound of election plus additional time for latency.
(also is strange that this is only mentioned for the C driver … while I would expect to be a setting mostly unrelated for the driver but related to the server instead)
Mongoose documentation instead suggest to use 5s for Lambda. But I have noticed some random connection timeout error (
MongooseServerSelectionError) when using 5s with an Atlas cluster.
Can you please confirm that 15s should be a good default value for Atlas connections?