Hello,
We are trying to connect DB cluster via node application and getting the following error
MongoServerSelectionError: Server selection timed out after 30000 ms
at Timeout._onTimeout (/home/ec2-user/test/node_modules/mongodb/lib/sdam/topology.js:293:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(1) {
we tried the solutions provided in forum like
- Setting directConnection=true
- useUnifiedTopology: true, useNewUrlParser: true, maxIdleTimeMS : 270000, minPoolSize : 2, maxPoolSize : 4
- useNewUrlParser: true, useUnifiedTopology: true
- useUnifiedTopology: false
- Changing the host file for DNS resolution.
All the above options did not work for us.
Node Version we are using is Node v16 and mongo v4.4.
We are successfully connecting to the cluster with mongo shell but not with node code.
Please suggest a solution to resolve the above mentioned issue.
Thank you