jstests/sharding/auth_slaveok_routing.js
/**
 * Checks if a query to the given collection will be routed to the secondary.
 *
 * @param {DBCollection} coll
 * @param {Object} query
 *
 * @return {boolean} true if query was routed to a secondary node.
 */
Checks if a query to the given collection will be routed to the secondary.
@param {DBCollection} coll
@param {Object} query

@return {boolean} true if query was routed to a secondary node.
Checks if a query to the given collection will be routed to the secondary . @param { DBCollection } coll @param { Object } query @return { boolean } true if query was routed to a secondary node .
function doesRouteToSec( coll, query ) {
    var explain = coll.find( query ).explain();
    assert.eq("SINGLE_SHARD", explain.queryPlanner.winningPlan.stage);
    var serverInfo = explain.queryPlanner.winningPlan.shards[0].serverInfo;
    var conn = new Mongo( serverInfo.host + ":" + serverInfo.port.toString());
    var cmdRes = conn.getDB( 'admin' ).runCommand({ isMaster: 1 });
    jsTest.log('isMaster: ' + tojson(cmdRes));
    return cmdRes.secondary;
}
function doesRouteToSec ( coll , query ) { var explain = coll . find ( query ) . explain ( ) ; assert . eq ( "SINGLE_SHARD" , explain . queryPlanner . winningPlan . stage ) ; var serverInfo = explain . queryPlanner . winningPlan . shards [ 0 ] . serverInfo ; var conn = new Mongo ( serverInfo . host + ":" + serverInfo . port . toString ( ) ) ; var cmdRes = conn . getDB ( 'admin' ) . runCommand ( { isMaster : 1 } ) ; jsTest . log ( 'isMaster: ' + tojson ( cmdRes ) ) ; return cmdRes . secondary ; }
Checks if a query to the given collection will be routed to the secondary.
Checks if a query to the given collection will be routed to the secondary .