mongodb
connection_error
ai_generated
true
MongoTimeoutError: Server selection timed out after 30000 ms
ID: mongodb/server-selection-timeout
82%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7 | active | — | — | — |
Root Cause
MongoDB driver cannot find a suitable server within timeout. Replica set not initialized, wrong connection string, or network issue.
genericWorkarounds
-
90% success Check replica set status
mongosh --eval 'rs.status()' # verify all members are healthy
Sources: https://www.mongodb.com/docs/manual/
-
92% success Verify connection string matches replica set name
mongodb://host1:27017,host2:27017/?replicaSet=myReplicaSet # must match rs.initiate name
-
85% success Check network connectivity between app and all replica members
All hosts in the connection string must be reachable from the application
Dead Ends
Common approaches that don't work:
-
Increase serverSelectionTimeoutMS to very large value
72% fail
Hides the real problem; application hangs for minutes before failing
-
Use directConnection=true to bypass replica set
68% fail
Bypasses read preference and failover; application breaks when the node goes down