Debugging the mongoose Connection to atlas

When I connect and it tells me very little about failure or success. As it fails a lot connecting from my windows 10. (same code) It has nothing to do with whitelisting because the IP isn’t changing and is already whitelisted. What can I do to understand where the driver is spending time during connecting? Is this indicative of the free Atlas platform.

On success, I generally get this: ( I added timings for benefit)

Connecting to Mongoose: 10:26:01 AM
App running on port 3000… 22 ms 10:26:01 AM
DB connection successful! 326 ms 10:26:02 AM

Connecting to Mongoose: 11:32:31 AM
App running on port 3000… 11:32:31 AM: 18 ms : pass
DB connection successful! 11:33:06 AM: 35111 ms : fail

Connecting to Mongoose: 11:36:08 AM
App running on port 3000… 11:36:08 AM: 20 ms : pass
UNHANDLED REJECTION! 💥 Shutting down… 11:37:23 AM: 75120 ms : fail
Error queryTxt ETIMEOUT Error: queryTxt ETIMEOUT
at QueryReqWrap.onresolve [as oncomplete] (dns.js:202:19)

My code below Mongoose 5.9.14 to Atlas

const DB = process.env.DATABASE.replace(


.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
serverSelectionTimeoutMS: 5000,
family: 4
.then(() => console.log(‘DB connection successful!’, tm(started)));

const port = process.env.PORT || 3000;

const server = app.listen(port, () => {
console.log(App running on port ${port}...);

I’m seeing failure rates on connections over 20% and that is being kind. On rare occasions, I see sub-second response times. Generally connections are made in 15 or 35 seconds. This is pretty consistent. Any 35-second connection won’t run on Heroku. I’m not sure a 15-second connection will get in done on Heroku.

Hi @Scott_Hopper, welcome!

Based on the error message that’s thrown, it’s failing on networking level. The failure seems to be related to attempting to resolve the SRV record.

Try connecting from a different internet network, and see whether you’re getting the same problem. For debugging purposes, you could also try changing the DNS settings to point to a public DNS.


Hi Wan,

Yes, definitely a DNS issue. I’m putting together a document on this topic, I measured 30 restarts and only twice did it respond under 15 seconds and once under 5 seconds. While my ISP generally very good response times via speed test generally getting 100+ Mbs. Their DNS seems to be awful. I’m also documenting my response time on public DNS’ where 1/2 second appears to be a long time.

1 Like