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.
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.
The dbHash command hashes collections in the current database only, and the collections field accepts bare collection names. If you include the database name in a collection name, such as accounts.us_accounts, dbHash finds no matching collection and returns the hash of an empty input on both clusters. To hash collections in more than one database, switch to each database in turn, run the command once per database, and compare the md5 values for each database separately.
Steps
Retrieve the Source Hash
Switch to the database that contains the synced collections, then run the dbHash command on the source cluster. In the collections field, list each collection included in the sync by name, without the database prefix. Then, return the md5 output field:
use accounts db.runCommand({ dbHash: 1, collections: [ "us_accounts", "eu_accounts", ... ]}).md5
9a1e4b7c2f8d3056ae91cbd4f72608b3
While running this command, retrieve the destination hash.
Retrieve the Destination Hash
Switch to the database that contains the synced collections, then run the dbHash command on the destination cluster. In the collections field, list each collection included in the sync by name, without the database prefix. Then, return the md5 output field:
use accounts db.runCommand({ dbHash: 1, collections: [ "us_accounts", "eu_accounts", ... ]}).md5
9a1e4b7c2f8d3056ae91cbd4f72608b3
Note the hash.