From the research I have done, mongodump doesn't have a built-in check to verify the integrity of a mongodump operation; at least, nothing apparent to the user. I may be wrong. If I am, please inform me. Otherwise, I'm sure I'm not the only one who wishes to verify their mongodump operation copied the data without any corruption or loss. What are the various methods others have used to insure the integrity of their mongodump files? If the method for doing so is inherently different on a sharded cluster, please answer how to do so on a single MongoDB instance and one that is sharded.
I have use db.collection.validate({full:true}) in the past which will validate the contents of the collection in question. Granted this is on a collection by collection basis to the best of my knowledge and is probably not to feasible for full DB restores. Since i will typically restore a collection or two only to a different env, i will do the .validate() before on the source and then after on the destination and compare the outputs.
Easy and simple way is to check using the DB stats
command which gives you more details about the count of each collections,views,objects and indexes. With this below command you can cross check source and destination databases whether the data is consistent post restoration.
use database
db.stats()
Note: Don't compare the dataSize or storageSize because the source db might have huge size since they have fragmented data.
© 2022 - 2024 — McMap. All rights reserved.