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.
Sobre esta tarefa
A comparação de hash não é possível com clusters fragmentados.
Se você precisar sincronizar um cluster fragmentado ou uma versão mais antiga do MongoDB, ou se os bloqueios forem inaceitáveis para o volume de trabalho do aplicativo, use um método de verificação diferente.
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.
Passos
Recuperar o hash de origem
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
Ao executar este comando, recupere o hash de destino.
Recuperar o hash de destino
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
Observe o hash.