0
votes

I'm having trouble connecting to a mongodb Atlas from a shared host, from my understanding it's because port 27017 is blocked by the firewall.
Any way to change the port number on mongodb Atlas?

this is the code on my nodejs file:

 mongoose.connect("mongodb+srv://<username>:<password>@test-nhowr.mongodb.net/test?retryWrites=true&w=majority", {
      useNewUrlParser: true,
      useCreateIndex: true,
    }).then(() => {
      console.log("Connected to DB");
    }).catch(err => {
      console.log('ERROR Connecting to db!: ', err.message);
    });

And this is the error I'm getting:

ERROR Connecting to db!: failed to connect to server [test-shard-00-00-nhowr.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 54.172.133.240:27017

2
Atlas uses whitelist access. Make sure your IP Address is whitelisted in Atlas. If the host IP Address is translated by network layers make sure to use the IP Address Atlas sees.barrypicker
It's not possible to change the port Atlas uses. If your current hosting prevents you from connecting to 27017, you should move to another provider that gives you the flexibility to do what you need.kevinadi

2 Answers

0
votes

Please replace and with the real credentials.

If you do not know how, just go to your atlas account in the left menu, find Security > Database Access > click "add new user" and create a username and a password then replace it with the placeholders.

0
votes

From my experience, most shared hosting platforms will not open this port. They want you to upgrade to a VPS or more expensive hosting option.

I was using Godaddy shared hosting and could not connect to mongodb Atlas. Port 27017 was not open, preventing a connection. I contacted Godaddy's technical support and they will not open this port, therefor you will not be able to connect. It does not matter what you do on your end if the hosting platform will not open port 27017.