Mongodb Compass: Connection timed out

I installed Mongodb on my remote server using this documentation. I have Ubuntu 16.04 on my remote server. Mongodb got installed successfully. I added the user like this:

use admin
db.createUser(
  {
    user: 'myuser',
    pwd: 'password',
    roles: [ { role: 'readWrite', db: 'mydb' } ]
  }
);

I also made changes in the mongod.conf like this:

net:
  port: 27017
  bindIp: 127.0.0.1,<server_ip>

security:
  authorization: 'enabled'

Now when I try to connect to mongodb using conneciton string like this:

mongodb://myuser:password@server_ip:27017/mydb

It gives me the following error:

connection timed out

What am I doing wrong here? I am using Laravel Forge to manage sever.

Can you connect by shell remotely as well as locally using same srv connect string?
Is port 27017 open to connections
Could be firewall blocking your connection

1 Like

I am not using the srv string as you can see in the question. Aftter ssh-ing into the server, I can connect to mongodb using the same string. There is no firewall blockage as I can connect to server from the same host but cant connect to mongodb. And this is the result of telnet:

telnet 139.162.147.195 27017
Trying 139.162.147.195...
telnet: Unable to connect to remote host: Connection timed out

Just for testing use 0.0.0.0 for bindIp and see if you can connect
Do you have the option to fill in individual params instead of connect string?
Use advance options and check ssh tunnel
Try different options

1 Like

As it turned out the port was not open and that was the only issue. Opened the port and now its working fine.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.