MongoServerSelectionError
Node.jsMongoSystemErrorconnectivitytopologytimeout
The driver could not select a suitable server for the operation within serverSelectionTimeoutMS
What is happening?
MongoServerSelectionError means the driver's SDAM (Server Discovery and Monitoring) system could not find a server matching the operation's read preference within the configured timeout (default 30s). This is the most common connection-related error in the Node.js driver. It wraps the underlying reason — there may be no reachable servers, no server matching the read preference, or the topology may still be initializing.
Common causes
- MongoDB server is not running or not reachable
- Incorrect connection string (wrong host, port, or SRV record)
- IP not in Atlas IP access list
- DNS resolution failure (common with mongodb+srv:// URIs)
- Network firewall blocking port 27017
- All replica set members are down or unreachable
- Read preference cannot be satisfied (e.g. secondary read with no secondaries)
- TLS/SSL misconfiguration
- Node.js 17+ IPv6 resolution issue (localhost resolves to ::1 instead of 127.0.0.1)