MongoDB启动时报错:exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog

MongoDB启动时报错:exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog
我的Mac升级到MacOS Catalina后,mongo就无法启动了,尝试了各种方法,就是起不来。于是考虑卸载了重装到最新版的mongodb-community 4.2

因为以前安装的时候使用的是brew命令安装,所以卸载起来也很方面,

$ brew uninstall mongo

卸载了我才发现brew install mongo已经不能再使用,因为mongodb已从Homebrew core中删除。具体删除原因看这里:Remove mongodb #43770

To our users: if you came here because mongodb stopped working for you, we have removed it from the Homebrew core formulas since it was migrated to a non open-source license.

大概原因就是MongoDB违背了开源协议,不再是开源项目。

被删除了就不能再使用brew命令安装了吗?其实不然,我们还可以使用mongodb团队维护的一个自定义的Homebrew tap库。先卸载旧的mongodb,然后从新的tap库重新安装新的mongodb。

$ brew uninstall mongodb
$ brew tap mongodb/brew //必须先执行这个命令,不然会提示找不到
$ brew install mongodb-community@4.2

可以参考官方的Mac上安装MongoDB Community 4.2文档:
https://docs.mongodb.com/manu…

按照文档安装都很顺利,但是当尝试着启动MongoDB时,问题就来了,还是起不来,日志输出如下:

2019-10-09T17:11:57.032+0800 I  STORAGE  [initandlisten] WiredTiger message [1570612317:32972][27322:0x11ac30d40], txn-recover: Set global recovery timestamp: (0,0)
2019-10-09T17:11:57.397+0800 I  STORAGE  [initandlisten] exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog. Collection: 0.objects, terminating
2019-10-09T17:11:57.398+0800 I  NETWORK  [initandlisten] shutdown: going to close listening sockets...
2019-10-09T17:11:57.399+0800 I  NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock

仔细查看日志,我们发现这句:exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog. Collection: 0.objects, terminating。大概意思就是说需要降级,我仔细分析了下,开始在卸载的时候数据目录并未随之删除,新版的配置文件,数据文件路径什么的都没变,于是我怀疑很有可能是以前的历史数据造成的,我将数据目录路径进行修改:
改前

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

改后

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb/data  //只修改了这里
net:
  bindIp: 127.0.0.1

然后再次启动

$ mongod --config /usr/local/etc/mongod.conf

启动成功,问题得到了解决。

the end

热门文章