首页 > 解决方案 > MongoDB 从 3.6 升级到 4.0:如何修复“collection does not have uuid in kvcatalog”异常?

问题描述

我在Rancher编排的容器化环境中运行 MongoDB 副本集。推出最新更新后,MongoDB已从3.6.x升级到4.0.x(最新)。

没有遵循升级路径,因此,当尝试绑定包含数据库存储的卷时,服务无法启动,并退出并出现以下异常:

STORAGE  [initandlisten] exception in initAndListen: MustDowngrade: Collection does not have UUID in KVCatalog. Collection: admin.system.version, terminating

即使尝试mongod使用该--repair选项启动,我也会得到相同的结果。我也尝试将容器回滚到MongoDB 3.6.16,但日志版本现在不兼容。

我们没有卷的快照,因此无法恢复数据(这不是生产环境)。我在网上找到的唯一解决方案mongodump不适用,因为它建议利用and mongorestore,需要一个正在运行的数据库并附加数据存储。

我的想法不多了,关于如何解决这个问题的任何建议?

标签: mongodbmongoimportmongodump

解决方案


我在 Mac OS 上使用 Homebrew 将 MongoDB 从 3.6 更新到 4.2,并遇到了类似的情况。

由于 formulamongodb已从 homebrew-core 中删除,因此 mongodb 团队维护了一个自定义 Homebrew tap

以下步骤是我使用 Homebrew 将 MongoDB 从 3.6 升级到 4.2 的解决方案:

  1. 从 Homebrew 卸载旧版本的 mongodb
# If you run mongodb in background service, stop it first.
brew services stop mongodb
# If you have multiple version of mongodb, you might need to add `--force` option for deleting all of them at once.
brew uninstall mongodb
  1. 从自定义 Homebrew 水龙头安装新的 mongodb
brew tap mongodb/brew
brew install mongodb-community@3.6
  1. 将 mongodb-community@3.6 添加到您的 PATH
echo 'export PATH="/usr/local/opt/mongodb-community@3.6/bin:$PATH"' >> ~/.bash_profile
  1. 重新启动终端,然后运行mongod

  2. 打开另一个选项卡或终端窗口以运行mongodump

  3. 终止mongod

  4. 卸载 mongodb-community@3.6 并重新安装 mongodb-community

brew uninstall mongodb-community@3.6
brew install mongodb-community
  1. 用旧的 mongo 数据结构删除旧数据
rm -rf /data/db/*
  1. mongod

  2. 打开另一个选项卡或终端窗口以运行mongorestore dump/

一旦mongorestore完成,mongod将被终止。您可以将 mongodb 作为后台服务运行,也可以mongod再次运行。mongo使用或 Robo 3T(以前的 Robomongo)打开 MongoDB ,你会看到你的数据和往常一样好。

希望能帮助到你。


推荐阅读