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

  1. MongoDB server is not running or not reachable
  2. Incorrect connection string (wrong host, port, or SRV record)
  3. IP not in Atlas IP access list
  4. DNS resolution failure (common with mongodb+srv:// URIs)
  5. Network firewall blocking port 27017
  6. All replica set members are down or unreachable
  7. Read preference cannot be satisfied (e.g. secondary read with no secondaries)
  8. TLS/SSL misconfiguration
  9. Node.js 17+ IPv6 resolution issue (localhost resolves to ::1 instead of 127.0.0.1)

Diagnostic Steps

Related Jira Issues