在mac上安装mongo

brewinstallmongodb

然后执行mongo出现以下错误:

lufeis-MacBook-Pro:~ lufei$ mongo
MongoDB shell version: 3.2.6
connecting to: test
2017-06-19T19:58:07.391+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2017-06-19T19:58:07.392+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

解决办法:

先找到mongo的安装位置

Alt text

找到mongo的位置,然后get info 找到mongo的真正位置

Alt text

进入安装路径,创建data文件夹和log文件夹

cd /usr/local/Cellar/mongodb/3.4.4/
mkdir data
mkdir log

cd bin
vim mongodb.conf

内容如下:

port=27017
dbpath=/usr/local/Cellar/mongodb/3.4.4/data/
logpath=/usr/local/Cellar/mongodb/3.4.4/log/mongodb.log
fork = true

然后执行

./mongod -f mongodb.conf

Alt text

标签: none

评论已关闭