Connection 9 to XXXX-XXXX-XXXX-shard-00-01.dkvup.mongodb.net:27017 timed out

Hello Guys!

I’m working with NodeJs and MongoDB and I’m connecting to MongoDB through Mongoose driver.

My setup:

  • NodeJS MongoDB Driver : 3.6.3
  • Mongoose : 5.10.0

Below is my connections options:-

{
    autoIndex: false,
    promiseLibrary: Promise,
    poolSize: 10,
    autoReconnect: true,
    reconnectTries: 30,
    reconnectInterval: 1 * 1000,
    connectTimeoutMS: 180 * 1000,
    socketTimeoutMS: 180 * 1000,
    keepAlive: true,
    keepAliveInitialDelay: 10 * 1000,
    useNewUrlParser: true
 }

Below is my connection string:-

mongodb+srv://${DB_USERNAME}:${DB_PASSWORD_ENCRYPTED)}@${DB_URI}/${mongoose.DB}?retryWrites=true&w=majority

I’m getting connection 9 to XXXX-XXXX-XXXX-shard-00-01.dkvup.mongodb.net:27017 timed out Error for one of the API.

Can anyone assist me on what causing the above error and possibly the best connection configuration on production environment to avoid such errors.

Hi @Rahul_Kosamkar and welcome in the MongoDB Community :smiley: !

First, the latest version of the driver is 3.6.7. It shouldn’t make a big difference but using the latest is usually the best option. I assume you are using the latest 4.4 version on MongoDB Atlas as well so everything is up-to-date and the versions are aligned? Mongoose’s latest version is 5.12.10 as well so maybe I would also align this.

Second, can you please confirm that, using the same user/password/URI on the same computer you are trying to run this code from, you can connect to this Atlas cluster using the mongo client or mongosh? If this doesn’t work I would check that the IP address of this server has been correctly added in the IP access list in Atlas. I would also check the user/password is correct.

Also, why do you have DB_PASSWORD_ENCRYPTED? The password isn’t encrypted. It should be in plain text.

Cheers,
Maxime.

1 Like