brew 安装mongo
brew 安装mongo 遇见的一些坑和报错
1. WiredTiger Permission denied
2. Found an invalid featureCompatibilityVersion document
3. Data directory /data/db not found., terminating
- 从2019年9月2日开始 ,HomeBrew 也从核心仓库 (#43770) 当中移除了mongodb 模块 ,MongoDB 已经宣布不再开源;
- 若果想继续使用
brew install mongodb
,MongoDB 官方提供了一个单独的 HomeBrew 的社区版本安装:https://github.com/mongodb/homebrew-brew
开始安装
brew tap mongodb/brew
很遗憾brew tap 的源无法加速,是从 mongodb.org 官方下载的安装包,等待一会吧brew install mongodb-community@4.2
brew tap mongodb/brew
配置文件:/usr/local/etc/mongod.conf
日志目录路径:/usr/local/var/log/mongodb
数据目录路径:/usr/local/var/mongodb
启动mongo
brew services start mongodb-community@4.2
brew services stop mongodb-community@4.2
brew services restart mongodb-community@4.2
报错 1
1 | wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied |
1 | 2020-04-13T14:20:17.647+0800 I STORAGE [initandlisten] Detected data files in /usr/local/var/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. |
将数据目录路径/usr/local/var/mongodb
目录赋值权限777sudo chmod -R 777 /usr/local/var/mongodb
报错 2
1 | Found an invalid featureCompatibilityVersion document If the current featureCompatibilityVersion is below 4.0, see the documentation on upgrading at http://dochub.mongodb.org/core/4.0-upgrade-fcv. |
1 | 2020-04-13T15:16:24.375+0800 F CONTROL [initandlisten] ** IMPORTANT: UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: BadValue: Invalid value for version, found 3.6, expected '4.2' or '4.0'. Contents of featureCompatibilityVersion document in admin.system.version: { _id: "featureCompatibilityVersion", version: "3.6" }. See http://dochub.mongodb.org/core/4.0-feature-compatibility.). If the current featureCompatibilityVersion is below 4.0, see the documentation on upgrading at http://dochub.mongodb.org/core/4.0-upgrade-fcv. |
只需将数据目录路径/usr/local/var/mongodb
里面内容清空在重新启动mongo即可
其他错误
以mongod 启动,报错
/data/db
文件夹不存在1
22020-04-13T15:16:24.375+0800 F STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
原因是:macOS 10.15版本不能创建
/data/db
1
2sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system可以mongod指定数据目录启动
mongod --dbpath '/Users/neo/data/db'
可以编辑配置文件
vim ~/.zshrc
在末尾添加以下内容,以后使用mongod启动1
alias mongod="mongod --dbpath '/Users/neo/data/db'"