您可以写入脚本来查询源集群,并将文档、索引、集合、元数据和视图与目标集群进行比较。
比较文档
您可以通过比较源集群和目标集群上的文档来验证同步。
在使用此方法验证数据传输之前,mongosync 必须处于 COMMITTED 状态。
比较索引
db.collection.getIndexes()要验证索引的传输,请在源集群和目标集群上运行 并比较结果。
比较元数据
To verify the transfer of metadata, run db.getCollectionInfos() on the source and destination clusters and compare the results.
比较分片键
要验证分片键是否传输到同步集合,请对 config.collections集合运行查询,以查找 _id 值为目标集合的命名空间的文档。 比较此文档在源集群和目标集群中的 key 值。
For example, for a collection named pets in the records database, you can verify the shard key using the following query in mongosh:
db.getSiblingDB("config").collections.find({ _id : "records.pets" })