Verifying Data with Custom Scripts
You can write a script to query your source cluster and compare the documents, indexes, collections, metadata, and views with the destination cluster.
Comparing Documents
You can verify sync by comparing documents on the source and destination clusters.
Before you can verify data transfer with this method, mongosync
must be in
the COMMITTED
state.
Comparing Indexes
To verify the transfer of indexes, run db.collection.getIndexes()
on the source and destination clusters and compare the results.
Comparing Metadata
To verify the transfer of metadata, run db.getCollectionInfos()
on the source and destination clusters and compare the results.
Comparing Shard Keys
To verify the transfer of shard keys to a synced collection, run a query on the
config.collections
collection to find a document whose _id
value is the
namespace of the target collection. Compare the key
value of this document
in the source and destination clusters.
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" })
{ "_id" : "records.pets", "lastmod" : ISODate("2021-07-21T15:48:15.193Z"), "timestamp": Timestamp(1626882495, 1), "key" : { "_id" : 1 }, "unique" : false, "lastmodEpoch" : ObjectId("5078407bd58b175c5c225fdc"), "uuid" : UUID("f8669e52-5c1b-4ea2-bbdc-a00189b341da") }