For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Verify with Hash Comparison

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.

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.

1

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.

2

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.

3

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

Rate this page