mongodb - mongodb - 使用 mongodump 和 mongorestore 后数据丢失?
问题描述
我注意到使用 mongodump 和 mongorestore 备份和恢复数据库后,我的 mongodb 的大小变小了:
> show dbs
iotdb1 0.611GB
iotdb2 0.476GB
原始大小为 0.611GB,但现在为 0.476GB。
这是正常的吗?
解决方案
简短的回答:
转储和恢复时,数据库大小无关紧要。文件只算重要。
解释:
Mongodump 不会备份,oplog
因此您可能会看到一些空间差异。此外,当您进行转储时data holes or bloat
,系统中已经存在的一些也会在您恢复它们时被删除。这是您在还原数据库后感觉数据库大小发生变化的两个主要原因。
确认:
您可以使用以下命令在两个数据库上查找之前和之后的所有文档大小的列表:
db.getCollectionNames().forEach(function(collection) { resultCount = db[collection].count(); print("" + collection + "的文档数: "+ resultCount); });
样本输出:
> db.getCollectionNames().forEach(function(collection) { resultCount = db[collection].count(); print("Number of documents for " + collection + ": "+ resultCount); });
Number of documents for credits: 17643
Number of documents for data: 500302
Number of documents for debts: 387
Number of documents for food: 309875
Number of documents for loans: 64926
Number of documents for payroll: 2436
Number of documents for tasks: 11564
Number of documents for salary: 883457
Number of documents for savings: 494
因此,通过上述查询,您可以轻松比较两个数据库并了解文档编号匹配。
推荐阅读
- java - 在同一个包中组织类的任何方式
- sql - SQL Developer 新列重置标识列设置
- copy - 从 S3 AVRO 文件复制到 Redshift 结果中的所有 Null 值的表
- ios - Angular :enter 动画不在 IOS 设备上运行
- javascript - Fade In without jQuery (fadeIn) - CSS 过渡不透明度和显示
- macos - Tableview 更新暮光区中的值
- internet-explorer - 是否有相当于“复制为卷曲”的 Internet Explorer?
- excel - 如何通过动态更新从 Excel VBA 导出 PDF
- amazon-web-services - 如何在 ECS/Fargate 容器中找到我的 IAM 委托人 ARN 或用户 ID?
- r - 是否有一个 R 函数可以匹配,如果 False 然后用 NA 替换它,如果为真,则进入列表并选择第一个数字,依此类推