使用 mongodump/mongoexport 将 MongoDB 数据迁移到更新版本

问题描述 投票:0回答:1

我当前使用的 MongoDB 版本是

4.0
。我想升级到
6.0
。根据官方文档,无法从
4.0
跳转到
6.0
。必须遵循以下顺序:
4.0 -> 4.2 -> 4.4 -> 5.0 -> 6.0

但是这是一个漫长的过程。必须测试 4 次,每次升级后测试一次。

所以,我想到创建新的

MongoDB 6.0
实例,并将所有数据从旧实例迁移到新实例。

我遇到了以下实用程序:

mongodump
mongoexport

mongoexport 的问题:(找到它这里

Avoid using mongoimport and mongoexport for full instance production backups.
They do not reliably preserve all rich BSON data types, 
because JSON can only represent a subset of the types supported by BSON.

mongodump 的问题:(找到它这里

using mongorestore to restore a 4.0 dump to 4.4 is not supported.
The reason for this is that collection options, index options,
and oplog entry formats can change between versions.
We do not test dump/restore from different versions so we cannot
guarantee that it will work correctly in all cases.
Because of this, it is not officially supported.

是否有针对上述问题的解决方法?

我对迁移过程中 MongoDB 的停机时间感到满意。我只想传输数据。不想转移索引之类的东西,可以在转移完成后在新实例中构建。

这可能吗?这种方法有什么缺陷吗?我应该坚持

4.0 -> 4.2 -> 4.4 -> 5.0 -> 6.0
吗?

谢谢!

database mongodb database-migration mongodump
1个回答
0
投票

好的,我在同一个地方,有 v4 版本,需要升级。 鉴于没有简单的方法来获得不涉及移植数据的升级路径,我将实现一个新的通用方法,我将创建一个控制台应用程序来推断/导入 JSON 中的所有数据库数据,每个

Collection 
独自存在
file.json

优点:以后可以将数据移植到任何DB,不再局限于DB版本和类型,以后需求变化时可以自由切换。

缺点:备份文件管理和额外的开发时间/精力。

© www.soinside.com 2019 - 2024. All rights reserved.