Im trying to connect to a mongodb server over a network but I cant get the connection to work.
I can connect like so on the local computer on which the server is running:
mongo localhost:27027
But connecting from a remote computer fails (where = the database hosts ip):
mongo <public_ip>:27027
Tue Mar 18 10:40:30 Error: couldn't connect to server <public_ip>:27017 shell/mongo.js:86
exception: connect failed
Notably this is response is different when the port is disallowed and rather than the exception: connect failed
error I get a timeout.
I have a firewall (ufw) but port 27027
is set to accept any connections. I also tried stopping the firewall altogether but had no joy.
What should I try to debug this problem, is there anything obvious I'm doing wrong?
Here's some extra info from the host computer that may be useful:
jon@lfmaster:~$ sudo ufw status
[sudo] password for jon:
Status: active
To Action From
-- ------ ----
80 ALLOW Anywhere
443 ALLOW Anywhere
22 ALLOW Anywhere
111 ALLOW Anywhere
2049 ALLOW Anywhere
27017 ALLOW Anywhere
28017 ALLOW Anywhere
80 ALLOW Anywhere (v6)
443 ALLOW Anywhere (v6)
22 ALLOW Anywhere (v6)
111 ALLOW Anywhere (v6)
2049 ALLOW Anywhere (v6)
27017 ALLOW Anywhere (v6)
28017 ALLOW Anywhere (v6)
–
jon@lfmaster:~$ sudo lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
...
mongod 1184 mongodb 6u IPv4 9911 0t0 TCP localhost:27017 (LISTEN)
mongod 1184 mongodb 8u IPv4 9913 0t0 TCP localhost:28017 (LISTEN)
Best Answer
If you need to use a nonstandard port you need to use the
--port
switch from the command linemongo <public ip> --port 27027