Search code examples
linuxmongodbubuntulinode

Cannot connect to remote mongodb server


I changed bindIp setting to

bindIp: 127.0.0.1, 0.0.0.0

in mongod.conf on my ubuntu server hosted on Linode and restarted mongod and status looks ok.

I opened mongodb port on ufw

sudo ufw status Status: active

To Action From -- ------ ---- 22/tcp ALLOW Anywhere 10000
ALLOW Anywhere Nginx Full
ALLOW Anywhere 3333
ALLOW Anywhere 27017
ALLOW Anywhere 22/tcp (v6)
ALLOW Anywhere (v6) 10000 (v6)
ALLOW Anywhere (v6) Nginx Full (v6)
ALLOW Anywhere (v6) 3333 (v6)
ALLOW Anywhere (v6) 27017 (v6)
ALLOW Anywhere (v6)

Connecting to it from my mac throws error:

mongo mongodb://admin:secret@ubuntuipaddress/fielddb?authSource=admin MongoDB shell version v3.6.2 connecting to: mongodb://ubuntuipaddress/fielddb?authSource=admin 2018-04-08T13:47:32.212 W NETWORK [thread1] Failed to connect to ubuntuipaddress:27017, in(checking socket for error after poll), reason: Connection refused 2018-04-08T13:47:32.214 E QUERY
[thread1] Error: couldn't connect to server ubuntuipaddress:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed

How to fix this issue?


Solution

  • The problem was wrong setting of bindIP in mmongod.conf. Changing to:

    bindIp: 127.0.0.1,ip_address_of_host_running_mondgod

    fixed the problem. Replace ip_address_of_host_running_mondgod with ip address of host running mongod like 137.142.177.4