Skip to content
Latchkey

MongoDB "mongodb+srv" URI SRV lookup failed in CI

A mongodb+srv:// URI makes the driver perform a DNS SRV query to discover the cluster nodes. When that query fails with querySrv ENOTFOUND or ETIMEOUT, the driver never learns the hosts and cannot connect.

What this error means

The driver throws "querySrv ENOTFOUND _mongodb._tcp.<host>" or "querySrv ETIMEOUT" for a mongodb+srv:// connection string, while a plain mongodb:// host would resolve.

node
MongoServerSelectionError: querySrv ENOTFOUND _mongodb._tcp.cluster0.abcde.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17)

Common causes

The runner resolver does not support or reach SRV

Some CI DNS setups drop SRV queries or a wildcard resolver returns nothing, so the SRV lookup fails even though A records resolve.

A wrong SRV host in the URI

The +srv host is misspelled, so the _mongodb._tcp.<host> record does not exist.

How to fix it

Use the standard seed-list URI instead of SRV

  1. In Atlas Connect, choose the non-SRV connection string (older driver option).
  2. Set MONGODB_URI to the mongodb://host1,host2,host3/?replicaSet=...&tls=true form.
  3. The driver connects directly without any SRV query.
Terminal
MONGODB_URI="mongodb://n1.mongodb.net:27017,n2.mongodb.net:27017/db?replicaSet=atlas-xxxx-shard-0&tls=true&authSource=admin&retryWrites=true&w=majority"

Confirm SRV records resolve on the runner

If you must keep +srv, verify the runner can query SRV; otherwise switch resolvers or the seed list.

Terminal
nslookup -type=SRV _mongodb._tcp.cluster0.abcde.mongodb.net
nslookup -type=TXT cluster0.abcde.mongodb.net

How to prevent it

  • Prefer the non-SRV seed list on CI networks that restrict DNS.
  • Keep the SRV host exactly as Atlas provides it.
  • Add a DNS smoke check before running the suite.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →