Server selection timed out

I am facing the below exception intermittently. I am using the connection as below

let connectionString = `mongodb://${data.username}:${data.password}@${clusterEndpoint}:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0`;
        return new Promise((resolve, reject) => {
                mongodb.connect(connectionString, { useUnifiedTopology: true }, (err, res) => {
                    if (err) {
                        reject(err);
                    } else {
                         resolve(res);
                    }
                })

            });

“errorMessage”:“MongoTimeoutError: Server selection timed out after 30000 ms”,“reason”:{“errorType”:“MongoTimeoutError”,“errorMessage”:“Server selection timed out after 30000 ms”,“name”:“MongoTimeoutError”,“stack”:[“MongoTimeoutError: Server selection timed out after 30000 ms”," at Timeout.setTimeout [as _onTimeout] (/var/task/node_modules/mongodb/lib/core/sdam/server_selection.js:308:9)“,” at ontimeout (timers.js:436:11)“,” at tryOnTimeout (timers.js:300:5)“,” at listOnTimeout (timers.js:263:5)“,” at Timer.processTimers (timers.js:223:10)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: MongoTimeoutError: Server selection timed out after 30000 ms”,” at process.on (/var/runtime/index.js:37:15)“,” at process.emit (events.js:198:13)“,” at process.EventEmitter.emit (domain.js:448:20)“,” at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)“,” at process._tickCallback (internal/process/next_tick.js:69:34)"]}

1 Like

Hi @Suresh_Nedunchezhian,

This message means no nodes/primary was found whitin the default 30s server selection period.

It might be a firewall thing or a DNS issue with the specified clusterEndpoint …

Make sure that with a mongoshell you can connect from this host. Moreover, please specify all hosts in replica set.

Best
Pavel

Hi @Pavel_Duchovny,

Thanks for looking into this.
If it is a firewall issue, then it has to happen all the times. But it happening for us only at sometimes.
One thing which i want to specify is we are using AWS DocDB.

Regards,
Suresh D.N.

1 Like

Hi @Suresh_Nedunchezhian,

This forum is to help with MongoDB related technologies and products I am not sure how I can help with other databases which are not MongoDB…

Best
Pavel