mac安装mongoDB的正确姿势
testmanzhang@TestMandeMBP corpora % brew tap mongodb/brew
testmanzhang@TestMandeMBP corpora % brew search mongodb
testmanzhang@TestMandeMBP corpora % brew install mongodb-community@7.0
依次执行上面的命令后开始安装mongoDB,但是安装过程中有很多报错,例如:
Error: openjdk: Failed to download resource "openjdk"
...
Error: pango: Failed to download resource "pango"
...
Error: ffmpeg@6: Failed to download resource "aom"
...
Error: ffmpeg: Failed to download resource "x265"
...
Error: gtk4: Failed to download resource "gtk4"
...
Error: libsoup: Failed to download resource "sqlite"
...
Error: python@3.13: Failed to download resource "python@3.13"
...
Error: gstreamer: Failed to download resource "ffmpeg"
...
Error: allure: Failed to download resource "openjdk"
...
Error: qt: Failed to download resource "qt"
...
Error: pyqt: Failed to download resource "qt"
...
Error: vtk: Failed to download resource "python@3.13"
...
Error: opencv: Failed to download resource "openvino"
...
报错有点多,可能是姿势不对,一个一个解决有点麻烦,可能有的跟mongoDB也没有关系,但是强迫症,看着不舒服,重装!
先卸载mongoDB:
testmanzhang@TestMandeMBP corpora % brew uninstall mongodb-community@7.0
testmanzhang@TestMandeMBP corpora % brew uninstall mongodb-database-tools
清除homebrew缓存:
testmanzhang@TestMandeMBP corpora % brew cleanup
删除mongoDB的残存文件:
testmanzhang@TestMandeMBP corpora % rm -rf /usr/local/var/mongodb
testmanzhang@TestMandeMBP corpora % rm -rf /opt/homebrew/var/mongodb
先更新一下homebrew:
testmanzhang@TestMandeMBP corpora % brew update
重新安装mongoDB:
testmanzhang@TestMandeMBP corpora % brew tap mongodb/brew
testmanzhang@TestMandeMBP corpora % brew install mongodb-community@7.0
这回安装比较顺利,没有报错!!!
启动mongoDB:
testmanzhang@TestMandeMBP corpora % brew services start mongodb/brew/mongodb-community@7.0
==> Successfully started `mongodb-community@7.0` (label: homebrew.mxcl.mongodb-community@7.0)
关闭mongoDB:
testmanzhang@TestMandeMBP corpora % brew services stop mongodb/brew/mongodb-community@7.0
Stopping `mongodb-community@7.0`... (might take a while)
==> Successfully stopped `mongodb-community@7.0` (label: homebrew.mxcl.mongodb-community@7.0)
连接mongoDB:
mongosh
testmanzhang@TestMandeMBP ~ % mongosh
Current Mongosh Log ID: 67e2a00939223a773679ef31
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.4.2
Using MongoDB: 7.0.17
Using Mongosh: 2.4.2
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
------
The server generated these startup warnings when booting
2025-03-25T20:22:23.392+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
test>