MongoDB "MongoServerSelectionError: getaddrinfo ENOTFOUND" in CI
DNS resolution failed: the driver asked the resolver for the cluster hostname and got ENOTFOUND. The host in your connection string is wrong, or the runner cannot resolve the Atlas SRV record.
What this error means
The driver fails server selection with "getaddrinfo ENOTFOUND <host>", naming the hostname from your mongodb+srv:// or mongodb:// URI. No server is ever reached.
MongoServerSelectionError: getaddrinfo ENOTFOUND cluster0.abcde.mongodb.net
at Timeout._onTimeout (/app/node_modules/mongodb/lib/sdam/topology.js:277:38)Common causes
A wrong or truncated hostname in MONGODB_URI
The Atlas host in the URI is misspelled, or a secret was set with a trailing newline or missing segment, so DNS has nothing to resolve.
The runner cannot query the SRV record
A mongodb+srv:// URI needs a DNS SRV lookup; a restricted CI network or blocked resolver returns ENOTFOUND for the underlying host.
How to fix it
Verify the exact host from Atlas
- Copy the connection string from Atlas (Connect, then Drivers) into the CI secret.
- Confirm the secret has no trailing whitespace or line break.
- Re-run and check the driver now resolves the host.
# quick DNS sanity check for an SRV URI
nslookup -type=SRV _mongodb._tcp.cluster0.abcde.mongodb.netFall back to the non-SRV seed list
If SRV lookups are blocked on the runner, use the standard mongodb:// seed list from Atlas (Connect shows it) so no SRV query is needed.
MONGODB_URI="mongodb://host1:27017,host2:27017,host3:27017/db?replicaSet=atlas-xxxx-shard-0&tls=true&authSource=admin"How to prevent it
- Store the exact Atlas connection string as a secret, trimmed of whitespace.
- Prefer the non-SRV seed list when the CI network blocks SRV lookups.
- Validate the URI in a smoke step before the full test suite.