Docs Menu
Docs Home
/
MongoDB Cluster-to-Cluster Sync
/ /

Verify with Hash Comparison

On this page

  • About This Task
  • Steps
  • Learn More

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.

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.

1

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.

2

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.

3

Compare the md5 values from each cluster. If both clusters return the same MD5 value, the sync was successful.

Back

Use Document Counts