卸载
到mongodb所在目录下
我本地是 /usr/local
执行
rm -rf mongodb

重装
# 进入 /usr/local
cd /usr/local

# 下载
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz

# 解压
sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz

# 重命名为 mongodb 目录

sudo mv mongodb-osx-x86_64-4.0.9/ mongodb
export PATH=/usr/local/mongodb/bin:$PATH




数据存放路径:

 sudo mkdir -p /usr/local/var/mongodb

 日志文件路径:

 sudo mkdir -p /usr/local/var/log/mongodb


确保当前用户对以上两个目录有读写的权限:

sudo chown user(电脑用户) /usr/local/var/mongodb
sudo chown user /usr/local/var/log/mongodb



在后台启动 mongodb:

mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork


出现报错
about to fork child process, waiting until server is ready for connections.
forked process: 40532
ERROR: child process failed, exited with 48


执行
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log

提示
Renamed existing log file","attr":{"oldLogPath":"/usr/local/mongodb/log/mongodb.log","newLogPath":"/usr/local/mongodb/log/mongodb.log.2021-03-06T15-37-59"

到/usr/local/mongodb/log/创建mongodb.log

出现报错
"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"

执行
sudo rm /tmp/mongodb-27017.sock

mongod --dbpath /usr/local/mongodb/data/db

启动成功


新建命令行窗口
执行
./mongo
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐