Cannot connect to mongodb using machine ip
For me I replaced the bindIp with bindIpAll: true (see http://docs.mongodb.org/manual/reference/configuration-options/ for details).
This is the content of my mongod.conf file.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIpAll: true
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
I just tested this on my Mac with Homebrew, works fine if you change the bind address. I suspect you probably just didn't get the config for bind correct?
Just so we have all the information, can you paste the output of ifconfig
please?
By default, MongoDB should listen on all interfaces, you shouldn't need to change the configuration, however, the Homebrew setup seems to override this (/usr/local/etc/mongod.conf):
# Only accept local connections
bind_ip = 127.0.0.1
Please kill MongoDB and run this (note the -v):
$ mongod --bind_ip 0.0.0.0 -v
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
all output going to: /usr/local/var/log/mongodb/mongo.log
Just paste your output for that please?
And then just try:
$ mongo --host 192.168.43.2 --verbose
MongoDB shell version: 2.4.6
Sat Aug 24 09:07:14.556 versionArrayTest passed
connecting to: 192.168.43.2:27017/test
Sat Aug 24 09:07:14.657 creating new connection to:192.168.43.2:27017
Sat Aug 24 09:07:14.657 BackgroundJob starting: ConnectBG
Sat Aug 24 09:07:14.657 connected connection!
Server has startup warnings:
Sat Aug 24 09:06:44.360 [initandlisten]
Sat Aug 24 09:06:44.360 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Obviously replace it with your IP address. Let us know how that goes.
No In fact, if you want to access the rest interface from any ip, you needn't set bind_ip to 0.0.0.0 in the mongod.conf, you only comment or remove the configuration item from it, as similar as
#bind_ip=127.0.0.1
And then, restart your service, you can find that you can access the rest service from the 28017 port from your machine
success:
- change service config file C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
# network interfaces (wjp: comment bindIp listening on all IPs)
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
- restart mongodb service (or restart computer);
- make sure machine level firewall open port 27017
- connect ok.