对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

使用哈希比较进行验证

您可以通过比较从源集群同步到目标集群的集合的 MD5 哈希来验证同步。虽然哈希比较可确保目标集群已收到来自源的所有更改,但dbHash 命令会锁定集群,在完成之前阻止其他写入。此进程也可能比使用文档计数进行验证慢得多。

无法对分片的集群进行哈希比较。

如果您需要同步分片集群或较早版本的 MongoDB,或者您的应用程序工作负载不接受这些锁,请使用其他验证方法。

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

运行此命令时,检索目标哈希值。

2

dbHash在目标集群上运行 命令。在collections 字段中,列出同步中包含的每个集合。然后,返回md5 输出字段:

db.runCommand({
dbHash: 1,
collections: [
"accounts.us_accounts",
"accounts.eu_accounts",
...
]}).md5
d41d8cd98f00b204e9800998ecf8427e

请注意哈希值。

3

比较每个集群的md5值。 如果两个集群返回相同的 MD5 值,则同步成功。

给本页内容打分