如果有安装过旧版本 Mongodb,需要先卸载旧版本,注意备份自己的数据。

brew services stop mongodb

brew uninstall homebrew/core/mongodb

安装最新版本 Mongodb,当前为 5.0

brew tap mongodb/brew
brew install mongodb-community

mongo --version

默认的配置文件、日志和数据路劲:

  • 配置文件: /usr/local/etc/mongod.conf
  • 日志目录: /usr/local/var/log/mongodb
  • 数据目录: /usr/local/var/mongodb

启动 Mongodb

brew services start mongodb-community

停止 Mongodb

brew services stop mongodb-community

如果不需要使用 Mongodb 了,卸载命令如下:

brew uninstall mongodb-community

brew uninstall mongodb-database-tools

使用 mongo 命令时控制台出现如下提示,mongo 命令即将被移除,请使用 mongosh 命令替代。

Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".

参考链接
https://github.com/mongodb/homebrew-brew
https://stackoverflow.com/questions/57856809/installing-mongodb-with-homebrew

标签: MongoDB