哪一个是Mongodump VS Mongoexport升级mongoDB数据库的首选?

时间:2017-06-15 08:51:36

标签: mongodb mongodump mongorestore

我的客户使用mongoDB 2.4并且由于此版本存在一些限制,我们已经为他们提供了升级到最新稳定版mongoDB 3.4.5的选项。

使用的初步测试 MongoDB 2.4中的mongodump 和Mongodb 3.4.3中的mongorestore工作正常,因为我可以看到导入的所有集合。

从文档mongorestore中没有提到它可以从旧版本的mongoDB恢复转储。

由于我们无法使用mongorestore,我可以使用" mongoexport"以旧的mongoDB 2.4的csv / json格式导出数据,并导入更新版本的mongoDB 3.4?

使用" mongoexport / mongoimport"可能存在哪些问题?而不是" mongodump"升级到更新版本的mongoDB 3.4?

注意:我将完全删除旧版本的mongoDB并安装较新版本的mongoDB

3 个答案:

答案 0 :(得分:16)

Mongodump and Mongorestore are better because:

  1. They run faster
  2. They preserve some data formats better than mongoexport and mongoimport, because the data is not translated from BSON into JSON and back.

As described in the MongoDB Docs on MongoImport:

WARNING
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. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

In addition, be very careful about the upgrade using mongorestore; just because the data is restored as it was previously, this does not mean that the new version of MongoDB can work with it. For example there were a sequence of changes to the authorisation model after v2.4 which means that you must first upgrade to v2.6, and only then to v3.0. There are similar structural changes at each major version, so it is recommended that you upgrade stepwise, one major version at a time i.e.

  1. v2.4 -> v2.6
  2. v2.6 -> v3.0
  3. v3.0 -> v3.2
  4. v3.2 -> v3.4

答案 1 :(得分:0)

From http://www.dba86.com/docs/mongo/2.4/core/import-export.html, mongoexport is supported from 2.4 version. Hence it should be the right tool for that. But still the document has warning message as well.

Warning: 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. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

Hope that helps!!!!

答案 2 :(得分:-5)

这两个工具(默认情况下)只会遍历_id索引以获取数据,然后将其写入磁盘。所以,是的,这两个工具都会同样影响你的工作集,这就是为什么我一般会建议在辅助设备上运行它们(如果可能的话,最好是隐藏的辅助设备)。 我假设您正在寻找mongodump相当于mongoexport中的--fields选项,只能转出特定的字段。查询选项可用于过滤结果,但不能与投影一起使用(选择返回的字段) - 这是在TOOLS-28中跟踪但尚未安排的功能请求。

相关问题