官术网_书友最值得收藏!

How to do it...

  1. Find your system's network interfaces and corresponding IP address(s) using the ifconfig command. For example, let's assume your system's IP address is 192.168.1.112.
  2. Start the mongod daemon without any special flags:
mongod --dbpath /data/db

This starts the mongod daemon which binds to all network interfaces on port 27017.

  1. In a separate Terminal, connect to your MongoDB server on this IP:
mongo 192.168.1.112:27017

You should see a MongoDB shell.

  1. Now stop the previously running mongod daemon (press Ctrl + C in the Terminal) and start the daemon to listen to your loopback interface:
mongod --dbpath /data/db --bind_ip 127.0.0.1
  1. In a separate Terminal, connect to your MongoDB server on this IP:
mongo 192.168.1.112:27017
  1. This time the mongo client will exit with a connect failed message. Let's connect to your loopback IP and it should work:
mongo 127.0.0.1:27017
  1. Stop the mongod daemon (press Ctrl + C in the Terminal) and let's start the daemon such that it binds to a different port as well:
mongod --dbpath /data/db --bind_ip 127.0.0.1 --port 27000
  1. In a separate Terminal, connect to your MongoDB server on this IP:
mongo 127.0.0.1:27000
  1. You should be connected to the server and see the mongo shell.
主站蜘蛛池模板: 滁州市| 临城县| 阿克陶县| 茶陵县| 临沧市| 青铜峡市| 安吉县| 江安县| 阳江市| 涟源市| 绵竹市| 连平县| 临沂市| 慈溪市| 浑源县| 云梦县| 化德县| 龙陵县| 南城县| 遵义县| 蕉岭县| 治多县| 博湖县| 弋阳县| 静乐县| 确山县| 黄石市| 丹江口市| 石棉县| 诸城市| 都匀市| 枣强县| 兴隆县| 潼关县| 宜章县| 柘荣县| 临猗县| 湄潭县| 永定县| 苏尼特右旗| 常宁市|