Assuming you are running Mongo in a VM for testing, it's handy for MongoDB to listen on all interfaces. This allows the host or other VMs to access the database. Assuming you are using a bridged network interface, you can just change bindIp: 127.0.0.1
to bindIpAll: true
in /etc/mongod.conf.
If you are using NAT, it will also be necessary to map a port on the host to port 27017 in the guest. To expose it for a single host, you can map a port on localhost to the guest. For instance:
Name | Protoco | Host IP | Host Port | Guest IP | Guest Port |
---|---|---|---|---|---|
Mongo | TCP | 127.0.01 | 27017 | 0.0.0.0 | 27017 |
localhost:27017
is the default database address used by the mongo
client, so no changes are needed. If you do change the port, the host and port must be supplied on the command line.
This article on Stack Overflow has more information: https://stackoverflow.com/questions/29109134/how-to-set-mongod-conf-bind-ip-with-multiple-ip-address/