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

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.
主站蜘蛛池模板: 清镇市| 黑河市| 福泉市| 项城市| 南投县| 南安市| 甘南县| 司法| 姜堰市| 封开县| 班戈县| 武威市| 锦州市| 新乡市| 西平县| 吴桥县| 贵南县| 扬州市| 靖边县| 镇康县| 蓬溪县| 洪湖市| 福建省| 大兴区| 博野县| 安国市| 宣汉县| 平谷区| 涟源市| 灯塔市| 大理市| 柏乡县| 新巴尔虎左旗| 合江县| 衢州市| 敦煌市| 千阳县| 巴南区| 石楼县| 安吉县| 安达市|