使用 Homebrew 安装 MongoDB
brew install mongodb
配置自动启动
1.链接 plist 文件
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
目录 /usr/local/opt/mongodb/ 是一个链接,指向 /usr/local/Cellar/mongodb/x.y.z x.y.z 是版本号,例如:( 4.0.3)
2.通过 launchctl 来启动和停止 mongod
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
3.你也可以使用命令 brew 来启动、停止和查看服务的状态。
brew services list | grep mongodb
brew services start mongodb
brew services stop mongodb
请注意:
默认的 plist 文件指定的 MongoDB 配置文件是 /usr/local/etc/mongod.conf, 配置中dbpath为/usr/local/var/mongdb。