简体   繁体   English

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

[英]Which one is the preferred choice Mongodump VS Mongoexport for upgrading mongoDB database?

My customer uses mongoDB 2.4 and as there are some limitations with this version, we have give them the option to upgrade to Latest stable mongoDB 3.4.5. 我的客户使用mongoDB 2.4,因为这个版本有一些限制,我们给他们选择升级到最新的稳定的mongoDB 3.4.5。

Initial testing of using mongodump in MongoDB 2.4 and mongorestore in Mongodb 3.4.5 worked fine as I can see all the collections imported. 在MongodDB 2.4中使用mongodump和在Mongodb 3.4.5中使用mongorestore的初步测试工作正常,因为我可以看到导入的所有集合。

From the documentation mongorestore it was not mentioned anywhere that it can restore the dumps from older versions of mongoDB. 从文档mongorestore中没有提到它可以从旧版本的mongoDB恢复转储。

As we cannot use the mongorestore , Can I use " mongoexport " to export the data in csv/json format of older mongoDB 2.4 , and import into newer version of mongoDB 3.4 ? 由于我们不能使用mongorestore,我可以使用“ mongoexport ”以旧的mongoDB 2.4的csv / json格式导出数据,并导入更新版本的mongoDB 3.4吗?

What are the possible problems of using "mongoexport/mongoimport" instead of "mongodump" to upgrade to newer version of mongoDB 3.4 ? 使用“mongoexport / mongoimport”而不是“mongodump”升级到更新版本的mongoDB 3.4会有什么问题?

NOTE: I will remove the older version of mongoDB completely and will install the newer version of mongoDB 注意:我将完全删除旧版本的mongoDB,并将安装较新版本的mongoDB

Mongodump and Mongorestore are better because: Mongodump和Mongorestore更好,因为:

  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. 它们比mongoexport和mongoimport更好地保留了一些数据格式,因为数据不会从BSON转换为JSON并返回。

As described in the MongoDB Docs on MongoImport : MongoImport上MongoDB Docs中所述

WARNING 警告
Avoid using mongoimport and mongoexport for full instance production backups. 避免使用mongoimport和mongoexport进行完整的实例生成备份。 They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. 它们不能可靠地保留所有丰富的BSON数据类型,因为JSON只能表示BSON支持的类型的子集。 Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality. 使用MongoDB备份方法中描述的mongodump和mongorestore来实现此类功能。

In addition, be very careful about the upgrade using mongorestore; 另外,使用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. 只是因为数据像以前一样被恢复,这并不意味着新版本的MongoDB可以使用它。 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 . 例如,在v2.4之后对授权模型进行了一系列更改,这意味着您必须先升级到v2.6,然后再升级到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 ie 每个主要版本都有类似的结构变化,因此建议您逐步升级,一次升级一个主要版本,

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

From http://www.dba86.com/docs/mongo/2.4/core/import-export.html , mongoexport is supported from 2.4 version. http://www.dba86.com/docs/mongo/2.4/core/import-export.html开始 ,2.4版本支持mongoexport。 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. 警告:避免使用mongoimport和mongoexport进行完整的实例生产备份。 They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. 它们不能可靠地保留所有丰富的BSON数据类型,因为JSON只能表示BSON支持的类型的子集。 Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality. 使用MongoDB备份方法中描述的mongodump和mongorestore来实现此类功能。

Hope that helps!!!! 希望有所帮助!!!!

Both tools (by default) will just walk the _id index to fetch the data and then write it out to disk. 这两个工具(默认情况下)只会遍历_id索引以获取数据,然后将其写入磁盘。 So, yes, both tools will similarly impact your working set which is why I would generally recommend running them against a secondary (preferably a hidden secondary if possible). 所以,是的,这两个工具都会同样影响你的工作集,这就是为什么我一般会建议在辅助设备上运行它们(如果可能的话,最好是隐藏的辅助设备)。 I assume you are looking for a mongodump equivalent of the --fields option from mongoexport to only dump out specific fields. 我假设您正在寻找mongodump相当于mongoexport中的--fields选项,只能转出特定的字段。 The query option can be used to filter results, but it cannot be used with a projection (to select the fields returned) - this is a feature request that is being tracked in TOOLS-28 but is not yet scheduled. 查询选项可用于过滤结果,但不能与投影一起使用(选择返回的字段) - 这是在TOOLS-28中跟踪但尚未安排的功能请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM