mongodb - 安装和运行 MongoDB - Mac 上的许多错误
问题描述
我正在尝试在我的 Mac 上安装 mongoDB。但是,我遇到了很多问题。
我首先通过运行以下命令使用 Homebrew 安装了 mongoDB:
brew tap mongodb/brew
brew install mongodb-community@4.2
然后使用:
brew services start mongodb-community@4.2
此时一切看起来都很好,直到我尝试在终端中运行:
mongod
起初我认为问题是我没有创建 /data/db 文件夹,所以我运行了:
sudo mkdir -p /data/db
这没有用。
然后我找到了一篇文章说Mac用户需要运行:
sudo mkdir -p /System/Volumes/Data/data/db
这有效..然后我跑了:
mongod --dbpath /System/Volumes/Data/data/db
并收到以下信息:
2020-02-09T20:36:07.667-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] MongoDB starting : pid=65406 port=27017 dbpath=/System/Volumes/Data/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] options: { storage: { dbPath: "/System/Volumes/Data/data/db" } }
2020-02-09T20:36:07.673-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-02-09T20:36:07.673-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:36:07.673-0500 I CONTROL [initandlisten] shutting down with code:48
我尝试运行:
sudo chown -Rv user /System/Volumes/Data/data/db
mongod
然后收到以下信息:
2020-02-09T20:36:52.247-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] MongoDB starting : pid=65410 port=27017 dbpath=/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] options: {}
2020-02-09T20:36:52.250-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-02-09T20:36:52.250-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:36:52.250-0500 I CONTROL [initandlisten] shutting down with code:48
对于 SocketException,我尝试了:
mongod --port 27018
并收到:
2020-02-09T20:37:39.191-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] MongoDB starting : pid=65414 port=27018 dbpath=/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] options: { net: { port: 27018 } }
2020-02-09T20:37:39.196-0500 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2020-02-09T20:37:39.196-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-02-09T20:37:39.196-0500 I - [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-02-09T20:37:39.196-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:37:39.196-0500 I CONTROL [initandlisten] shutting down with code:100
我似乎无法弄清楚发生了什么,因为我一直在按照我在 StackOverflow 上从其他人那里找到的所有步骤来解决这个确切的问题。
解决方案
在做了更多的研究并查看了上面的评论之后,似乎在通过 homebrew 安装 MongoDB 时,您将使用以下命令:
brew services start mongodb-community
然后在新选项卡中:
mongo
这将成功启动 mongo。我仍然不能 100% 确定为什么会mongod
回避错误,但据我所知,上述方法有效。
推荐阅读
- c++ - 将向量写入文件c ++
- flutter - 如何在 Flutter 的底部导航中处理后退导航
- python - 使用下标定义xlabel或ylabel时如何在python中禁用斜体字体
- python - 如何从for循环中获取用户输入的数据到kivymd中的python文件
- android-studio - 如何在android studio中平滑位图(png)的边缘
- dataset - 无法在数据标签 MLStudio 中设置数据集类型
- angular - Angular Ionic 离子日期时间选择器
- javascript - 如何在不使用伪状态的情况下在悬停时在现有边框底部上设置边框底部动画
- php - 无法在 php 系统中运行 imagemagick convert
- swift - 设置最初可见的项目 LazyGrid (swiftUI)