Installed Mongo using homebrew. If I type mongo on shell, it gets connected to test. But when I type the ip address of the local machine instead of

mongo --host --verbose

It gives me error message

MongoDB shell version: 2.4.6
Fri Aug 23 15:18:27.552 versionArrayTest passed
connecting to:
Fri Aug 23 15:18:27.579 creating new connection to: 
Fri Aug 23 15:18:27.579 BackgroundJob starting: ConnectBG
Fri Aug 23 15:18:27.580 Error: couldn't connect to server at src/mongo/shell/mongo.js:147
Fri Aug 23 15:18:27.580 User Assertion: 12513:connect failed

Have tried modifying the mongo.conf by commenting bind_ip or by changing the ip address from to but no luck. This should be simple but have no clue now. Using mac.


Update: As requested. This works after I have made the changes as you suggested.

ifconfig output

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
   inet netmask 0xff000000 
   inet6 ::1 prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
   ether XX:XX:XX:
   media: autoselect (none)
   status: inactive
   ether XX:XX:XX:XX:01 
   inet6 XXXX:XXXX:XXXX: %en1 prefixlen 64 scopeid 0x5 
   inet netmask 0xffffff00 broadcast
   media: autoselect
   status: active
   ether XX:XX:XX:XX:XX
   media: autoselect
   status: inactive
   lladdr XX:XX:XX:XX
   media: autoselect <full-duplex>
   status: inactive

Output when executing command mongo --host --verbose

MongoDB shell version: 2.4.5
Fri Aug 23 16:42:09.806 versionArrayTest passed
connecting to:
Fri Aug 23 16:42:09.837 creating new connection to:
Fri Aug 23 16:42:09.837 BackgroundJob starting: ConnectBG
Fri Aug 23 16:42:10.129 connected connection!
Server has startup warnings: 
Fri Aug 23 16:41:59.025 [initandlisten] 
Fri Aug 23 16:41:59.025 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

File mongod.conf

# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb

# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true

# Only accept local connections
bind_ip =`

Solution 1

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 =

Please kill MongoDB and run this (note the -v):

$ mongod --bind_ip -v
warning: bind_ip of 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 --verbose
MongoDB shell version: 2.4.6
Sat Aug 24 09:07:14.556 versionArrayTest passed
connecting to:
Sat Aug 24 09:07:14.657 creating new connection to:
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.

Solution 2


  1. change service config file C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
# network interfaces (wjp: comment bindIp listening on all IPs)
  port: 27017
#  bindIp:
  1. restart mongodb service (or restart computer);
  2. make sure machine level firewall open port 27017
  3. connect ok.

Solution 3

No In fact, if you want to access the rest interface from any ip, you needn't set bind_ip to in the mongod.conf, you only comment or remove the configuration item from it, as similar as


And then, restart your service, you can find that you can access the rest service from the 28017 port from your machine

Solution 4

For me I replaced the bindIp with bindIpAll: true (see for details).

This is the content of my mongod.conf file.

# mongod.conf

# for documentation of all options, see:

# Where and how to store data.
  dbPath: /var/lib/mongodb
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
  port: 27017
  # bindIp:
  bindIpAll: true

# how the process runs
  timeZoneInfo: /usr/share/zoneinfo





## Enterprise-Only Options:



Solution 5

Note: Below configuration is for windows 10 & MongoDB 4.0

There are two ways to configure this.

  1. Using shell commands.
  2. Or through mongod.cfg.

Using shell commands

First open the cmd as administrator and go to --YourPath--\MongoDB\Server\4.0\bin

  1. If you already running the MongoDB service then run this command or else, go to second point.mongod --remove

  2. Then set the path for data folder, log file and ip bind using the below command

    mongod --dbpath "C:\Program Files\MongoDB\Server\4.0\data" --logpath "C:\Program Files\MongoDB\Server\4.0\log\mongod.log" --bind_ip "" --install --serviceName "MongoDB"

caution: This ip configuration gives access to your DB throughout the network.

  1. Now go to services.msc and find the MongoDB, then Right click -> Start the service.

Through mongod.cfg

MongoDB has a very good documentation for Configuration here.

Just change the bindIp: to bindIp: Then restart the service using the #3 point from the above topic.