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

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.
主站蜘蛛池模板: 犍为县| 饶平县| 耒阳市| 石渠县| 抚顺县| 澄江县| 岫岩| 中阳县| 谢通门县| 镇江市| 东丰县| 仙桃市| 佛坪县| 镇远县| 绍兴县| 凭祥市| 赫章县| 广德县| 武陟县| 西华县| 东海县| 望奎县| 包头市| 马公市| 肃宁县| 尖扎县| 阿坝县| 含山县| 闵行区| 综艺| 德庆县| 石家庄市| 双鸭山市| 板桥市| 鄢陵县| 读书| 宣恩县| 神木县| 诏安县| 迁安市| 浙江省|