jstests/libs/fixture_helpers.js
/**
     * Runs the function given by 'func' passing the database given by 'db' from each shard nodes in
     * the fixture (besides the config servers). Returns the array of return values from executed
     * functions. If the fixture is a standalone, will run the function on the database directly.
     */
Runs the function given by 'func' passing the database given by 'db' from each shard nodes in
the fixture (besides the config servers). Returns the array of return values from executed
functions. If the fixture is a standalone, will run the function on the database directly.
Runs the function given by ' func ' passing the database given by ' db ' from each shard nodes in the fixture ( besides the config servers ) . Returns the array of return values from executed functions . If the fixture is a standalone will run the function on the database directly .
function mapOnEachShardNode({db, func, primaryNodeOnly}) {
        function getRequestedConns(host) {
            const conn = new Mongo(host);
            const isMaster = conn.getDB("test").isMaster();
            if (isMaster.hasOwnProperty("setName")) {
                const rs = new ReplSetTest(host);
                return primaryNodeOnly ? [rs.getPrimary()] : rs.nodes;
            } else {
                return [conn];
            }
        }
        let connList = [];
        if (isMongos(db)) {
            const shardObjs = db.getSiblingDB("config").shards.find().sort({_id: 1}).toArray();
            for (let shardObj of shardObjs) {
                connList = connList.concat(getRequestedConns(shardObj.host));
            }
        } else {
            connList = connList.concat(getRequestedConns(db.getMongo().host));
        }
        return connList.map((conn) => func(conn.getDB(db.getName())));
    }
function mapOnEachShardNode ( { db , func , primaryNodeOnly } ) { function getRequestedConns ( host ) { const conn = new Mongo ( host ) ; const isMaster = conn . getDB ( "test" ) . isMaster ( ) ; if ( isMaster . hasOwnProperty ( "setName" ) ) { const rs = new ReplSetTest ( host ) ; return primaryNodeOnly ? [ rs . getPrimary ( ) ] : rs . nodes ; } else { return [ conn ] ; } } let connList = [ ] ; if ( isMongos ( db ) ) { const shardObjs = db . getSiblingDB ( "config" ) . shards . find ( ) . sort ( { _id : 1 } ) . toArray ( ) ; for ( let shardObj of shardObjs ) { connList = connList . concat ( getRequestedConns ( shardObj . host ) ) ; } } else { connList = connList . concat ( getRequestedConns ( db . getMongo ( ) . host ) ) ; } return connList . map ( ( conn ) => func ( conn . getDB ( db . getName ( ) ) ) ) ; }
Runs the function given by 'func' passing the database given by 'db' from each shard nodes in
 the fixture (besides the config servers).
Runs the function given by ' func ' passing the database given by ' db ' from each shard nodes in the fixture ( besides the config servers ) .
// It's a repl set. // It's a standalone.