jstests/sharding/compound_hashed_shard_key_targeting.js
/**
 * Finds the shard to which hashed value of 'fieldValue' belongs to and validates that there exists
 * a single profiler entry on that shard, for the given 'filter'. Also verifies that no entry
 * matching 'filter' is present on the other shard.
 */
Finds the shard to which hashed value of 'fieldValue' belongs to and validates that there exists
a single profiler entry on that shard, for the given 'filter'. Also verifies that no entry
matching 'filter' is present on the other shard.
Finds the shard to which hashed value of ' fieldValue ' belongs to and validates that there exists a single profiler entry on that shard for the given ' filter ' . Also verifies that no entry matching ' filter ' is present on the other shard .
function verifyProfilerEntryOnCorrectShard(fieldValue, filter) {
    const hashedValue = convertShardKeyToHashed(fieldValue);
    const nsOrUUID = (function() {
        const coll = st.s.getDB('config').collections.findOne({_id: ns});
        if (coll.timestamp) {
            return {$eq: ['$uuid', coll.uuid]};
        } else {
            return {$eq: ['$ns', ns]};
        }
    }());
    const chunk = st.s.getDB('config').chunks.findOne({
        $expr: {$and: [{$lte: ['$min.a', hashedValue]}, {$gt: ['$max.a', hashedValue]}, nsOrUUID]}
    });
    assert(chunk, findChunksUtil.findChunksByNs(st.s.getDB('config'), ns).toArray());
    const [targetShard, otherShard] =
        (chunk.shard == st.shard0.shardName) ? [st.shard0, st.shard1] : [st.shard1, st.shard0];
    profilerHasSingleMatchingEntryOrThrow({profileDB: targetShard.getDB(kDbName), filter: filter});
    profilerHasZeroMatchingEntriesOrThrow({profileDB: otherShard.getDB(kDbName), filter: filter});
}
function verifyProfilerEntryOnCorrectShard ( fieldValue , filter ) { const hashedValue = convertShardKeyToHashed ( fieldValue ) ; const nsOrUUID = ( function ( ) { const coll = st . s . getDB ( 'config' ) . collections . findOne ( { _id : ns } ) ; if ( coll . timestamp ) { return { $eq : [ '$uuid' , coll . uuid ] } ; } else { return { $eq : [ '$ns' , ns ] } ; } } ( ) ) ; const chunk = st . s . getDB ( 'config' ) . chunks . findOne ( { $expr : { $and : [ { $lte : [ '$min.a' , hashedValue ] } , { $gt : [ '$max.a' , hashedValue ] } , nsOrUUID ] } } ) ; assert ( chunk , findChunksUtil . findChunksByNs ( st . s . getDB ( 'config' ) , ns ) . toArray ( ) ) ; const [ targetShard , otherShard ] = ( chunk . shard == st . shard0 . shardName ) ? [ st . shard0 , st . shard1 ] : [ st . shard1 , st . shard0 ] ; profilerHasSingleMatchingEntryOrThrow ( { profileDB : targetShard . getDB ( kDbName ) , filter : filter } ) ; profilerHasZeroMatchingEntriesOrThrow ( { profileDB : otherShard . getDB ( kDbName ) , filter : filter } ) ; }
Finds the shard to which hashed value of 'fieldValue' belongs to and validates that there exists
 a single profiler entry on that shard, for the given 'filter'.
Finds the shard to which hashed value of ' fieldValue ' belongs to and validates that there exists a single profiler entry on that shard for the given ' filter ' .
// Find the chunk to which 'hashedValue' belongs to. We use $expr here so that the $lte and $gt // comparisons occurs across data types.