Unable to connect to mongo on remote server

安稳与你 提交于 2019-12-03 03:10:30

make sure that mongodb daemon is running, and listening on 0.0.0.0, but not 127.0.0.1 port

for example, for my local mongodb, it has this config:

[vodolaz095@steel ~]$ cat /etc/mongod.conf 
##
### Basic Defaults
##

# Comma separated list of ip addresses to listen on (all local ips by default)
bind_ip = 127.0.0.1

# Specify port number (27017 by default)
#port = 27017

for mongodb server to listen for remote connections, you can change

# Comma separated list of ip addresses to listen on (all local ips by default)
bind_ip = 0.0.0.0

With mongoDB server version 3.6.4, Ubuntu 16.4.4 I solved this by setting the net section in /etc/mongod.conf like this:

net:
  port: 27017
  bindIpAll: true
#  bindIp: 127.0.0.1

The issue was bindIp didn't change. There was some issue in restarting mongo from my side.

The habit should be to verify if the bindIp actually changed or not. (using sudo netstat -tulpn | grep 27017)

Make sure you have a daemon running on your machine1 which listen to port 27017. We were getting the same error and found that daemon was not running.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!