Verify with Hash Comparison
On this page
You can verify sync by comparing MD5 hashes of collections synced from the
source cluster to the destination cluster. While hash comparison ensures
that the destination cluster has received all changes from the source, the
dbHash
command locks the cluster, preventing additional writes
until it completes. This process can also be much slower than verification
using document counts.
About This Task
Hash comparison is not possible with sharded clusters. It also does not work for standalone servers and replica sets that use MongoDB 4.4 or earlier releases, since the document field order can vary.
If you need to sync a sharded cluster or an older release of MongoDB, or if the locks are unacceptable for your application workload, use a different verification method.
Steps
Retrieve the Source Hash
Run the dbHash
command on the source cluster.
In the collections
field, list each collection included
in the sync. Then, return the md5
output field:
db.runCommand({ dbHash: 1, collections: [ "accounts.us_accounts", "accounts.eu_accounts", ... ]}).md5
d41d8cd98f00b204e9800998ecf8427e
While running this command, retrieve the destination hash.
Retrieve the Destination Hash
Run the dbHash
command on the destination cluster.
In the collections
field, list each collection included
in the sync. Then, return the md5
output field:
db.runCommand({ dbHash: 1, collections: [ "accounts.us_accounts", "accounts.eu_accounts", ... ]}).md5
d41d8cd98f00b204e9800998ecf8427e
Note the hash.