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

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.
主站蜘蛛池模板: 芒康县| 甘洛县| 偏关县| 凤翔县| 修文县| 靖远县| 宜良县| 鹤峰县| 响水县| 丰县| 甘肃省| 陆川县| 彭阳县| 巩义市| 商河县| 积石山| 福清市| 潼关县| 开鲁县| 上思县| 兴城市| 海阳市| 吐鲁番市| 桓仁| 永定县| 新乡市| 锦州市| 渭源县| 集贤县| 鹤山市| 灌阳县| 宜州市| 兰州市| 元谋县| 亚东县| 开远市| 江安县| 绥德县| 长子县| 多伦县| 呼伦贝尔市|