jstests/sharding/zone_changes_hashed.js
/**
 * Adds each shard to the corresponding zone in zoneTags, and makes the zone range equal
 * to the chunk range of the shard. Assumes that there are no chunk holes on each shard.
 */
Adds each shard to the corresponding zone in zoneTags, and makes the zone range equal
to the chunk range of the shard. Assumes that there are no chunk holes on each shard.
Adds each shard to the corresponding zone in zoneTags and makes the zone range equal to the chunk range of the shard . Assumes that there are no chunk holes on each shard .
function addShardsToZonesAndAssignZoneRanges(st, ns, shardChunkBounds, shardTags) {
    let zoneChunks = {};
    for (let [shardName, chunkBounds] of Object.entries(shardChunkBounds)) {
        let zoneName = shardTags[shardName][0];
        let rangeMin = {x: MaxKey};
        let rangeMax = {x: MinKey};
        for (let bounds of chunkBounds) {
            if (chunkBoundsUtil.lt(bounds[0], rangeMin)) {
                rangeMin = bounds[0];
            }
            if (chunkBoundsUtil.gte(bounds[1], rangeMax)) {
                rangeMax = bounds[1];
            }
        }
        zoneChunks[zoneName] = chunkBounds;
        assert.commandWorked(st.s.adminCommand({addShardToZone: shardName, zone: zoneName}));
        assert.commandWorked(st.s.adminCommand(
            {updateZoneKeyRange: ns, min: rangeMin, max: rangeMax, zone: zoneName}));
    }
    return zoneChunks;
}
function addShardsToZonesAndAssignZoneRanges ( st , ns , shardChunkBounds , shardTags ) { let zoneChunks = { } ; for ( let [ shardName , chunkBounds ] of Object . entries ( shardChunkBounds ) ) { let zoneName = shardTags [ shardName ] [ 0 ] ; let rangeMin = { x : MaxKey } ; let rangeMax = { x : MinKey } ; for ( let bounds of chunkBounds ) { if ( chunkBoundsUtil . lt ( bounds [ 0 ] , rangeMin ) ) { rangeMin = bounds [ 0 ] ; } if ( chunkBoundsUtil . gte ( bounds [ 1 ] , rangeMax ) ) { rangeMax = bounds [ 1 ] ; } } zoneChunks [ zoneName ] = chunkBounds ; assert . commandWorked ( st . s . adminCommand ( { addShardToZone : shardName , zone : zoneName } ) ) ; assert . commandWorked ( st . s . adminCommand ( { updateZoneKeyRange : ns , min : rangeMin , max : rangeMax , zone : zoneName } ) ) ; } return zoneChunks ; }
Adds each shard to the corresponding zone in zoneTags, and makes the zone range equal
 to the chunk range of the shard.
Adds each shard to the corresponding zone in zoneTags and makes the zone range equal to the chunk range of the shard .