Mac下 mongodb 的安装与运行
本文写与2020-06-16,此方法目前有效
2018、2019可使用brew install mongod直接安装 因为后来被收购,所以不支持直接安装 此教程按照官网配置
mongodb官网:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
brew下载方式(需homebrew提前安装brew)
brew tap mongodb/brew
brew install mongodb-community@4.2
#(开启服务)To run MongoDB (i.e. the mongod process) as a macOS service, issue the following:
brew services start mongodb-community@4.2
#(停止服务)To stop a mongod running as a macOS service, use the following command as needed:
brew services stop mongodb-community@4.2
#To run MongoDB (i.e. the mongod process) manually as a background process, issue the following:
#mongod --config /usr/local/etc/mongod.conf --fork
安装后的默认配置文件路径如下:
#配置文件:/usr/local/etc/mongod.conf
#日志目录路径:/usr/local/var/log/mongodb
#数据目录路径:/usr/local/var/mongodb
有了 brew 后,启动 Mongo 和停止 Mongo 就很方便了。
可选 设置别名
注意:以下命令只对bash有效,若你的terminal为zsh,则点此去查看设置方式
设置别名方式:在用户家目录下编辑.bashrc添加以下两行:
alias mongo-start = 'brew services start mongodb-community@4.2'
alias mongo-stop = 'brew services stop mongodb-community@4.2'
添加完成后执行
source .bashrc
#启动
mongo-start
#运行
mongo
#停止
mongo-sto
#若想取消别名则
unalias mongo-start
unalias mongo-stop