jstests/sharding/libs/zone_changes_util.js
/**
 * Asserts that the docs are on the shards that own their corresponding chunks.
 *
 * @param shardChunkBounds {Object} a map from each shard name to an array of the bounds for all
 *                                  the chunks on the shard. Each pair of chunk bounds is an array
 *                                  of the form [minKey, maxKey].
 * @param shardKey         {Object} a map from each shard key field to 1 if the collection uses
 *                                  range based sharding and "hashed" if the collection uses
 *                                  hashed sharding. (i.e. equivalent to the value passed for the
 *                                  "key" field for the shardCollection command).
 */
Asserts that the docs are on the shards that own their corresponding chunks.
@param shardChunkBounds {Object} a map from each shard name to an array of the bounds for all
the chunks on the shard. Each pair of chunk bounds is an array
of the form [minKey, maxKey].
@param shardKey         {Object} a map from each shard key field to 1 if the collection uses
range based sharding and "hashed" if the collection uses
hashed sharding.
Asserts that the docs are on the shards that own their corresponding chunks . @param shardChunkBounds { Object } a map from each shard name to an array of the bounds for all the chunks on the shard . Each pair of chunk bounds is an array of the form [ minKey maxKey ] . @param shardKey { Object } a map from each shard key field to 1 if the collection uses range based sharding and " hashed " if the collection uses hashed sharding .
function assertDocsOnShards(st, ns, shardChunkBounds, docs, shardKey) {
    for (let doc of docs) {
        let docShardKey = {};
        for (const [k, v] of Object.entries(shardKey)) {
            docShardKey[k] = (v == "hashed") ? convertShardKeyToHashed(doc[k]) : doc[k];
        }
        let shard = chunkBoundsUtil.findShardForShardKey(st, shardChunkBounds, docShardKey);
        assert.eq(1,
                  shard.getCollection(ns).count(doc),
                  "expected to find doc " + tojson(doc) + " on shard \"" + shard.shardName + "\"");
    }
}
function assertDocsOnShards ( st , ns , shardChunkBounds , docs , shardKey ) { for ( let doc of docs ) { let docShardKey = { } ; for ( const [ k , v ] of Object . entries ( shardKey ) ) { docShardKey [ k ] = ( v == "hashed" ) ? convertShardKeyToHashed ( doc [ k ] ) : doc [ k ] ; } let shard = chunkBoundsUtil . findShardForShardKey ( st , shardChunkBounds , docShardKey ) ; assert . eq ( 1 , shard . getCollection ( ns ) . count ( doc ) , "expected to find doc " + tojson ( doc ) + " on shard \"" + shard . shardName + "\"" ) ; } }
Asserts that the docs are on the shards that own their corresponding chunks.
Asserts that the docs are on the shards that own their corresponding chunks .