MongoDB Failed To Connect – Error 10061

I recently built a single MongoDB server on a Ubuntu 16.04 LTS server, and I was trying to connect to it with mongoimport from a Windows machine.

C:\Program Files\MongoDB\Server\3.2\bin>mongo –host ubuntu-mongodb
MongoDB shell version: 3.2.8
connecting to: ubuntu-mongodb:27017/test
2017-11-26T17:22:21.224+0000 W NETWORK [thread1] Failed to connect to, reason: errno:10061 No connection could be made because the target machine actively refused it.
2017-11-26T17:22:21.224+0000 E QUERY [thread1] Error: couldn’t connect to server ubuntu-mongodb:27017, connection attempt failed :

A local connection was working using the mongo shell, but not remotely, so I started puzzling about firewalls either on Windows or Ubuntu. As a further test, I tried a connection from another Windows machine – a Windows 10 laptop – with the same result. The remote Ubuntu server obviously responded to pings.

Drawing a blank with firewalls, I did start to consider whether MongoDB disables remote connections by default, something that has become increasingly common with database platforms for obvious reasons. I had a quick look at the mongodb.conf file, and the local loopback IP address stood out for the bind_ip parameter:

# Listen to local interface only. Comment out to listen on all interfaces.

I opened the mongodb.conf file in VI, commented out the line with bind_ip – and then spend far too many minutes wondering why it wouldn’t let me save it. I’d forgotten to sudo to VI.