jstests/core/explain_count.js
/**
 * Given explain output 'explain' at executionStats level verbosity,
 * confirms that the root stage is COUNT and that the result of the
 * count is equal to 'nCounted'.
 */
Given explain output 'explain' at executionStats level verbosity,
confirms that the root stage is COUNT and that the result of the
count is equal to 'nCounted'.
Given explain output ' explain ' at executionStats level verbosity confirms that the root stage is COUNT and that the result of the count is equal to ' nCounted ' .
function checkCountExplain(explain, nCounted) {
    printjson(explain);
    var execStages = explain.executionStats.executionStages;
    if ("SINGLE_SHARD" == execStages.stage) {
        var countStage = execStages.shards[0].executionStages;
        assert.eq(countStage.stage, "COUNT", "root stage on shard is not COUNT");
        assert.eq(countStage.nCounted, nCounted, "wrong count result");
    }
    else {
        assert.eq(execStages.stage, "COUNT", "root stage is not COUNT");
        assert.eq(execStages.nCounted, nCounted, "wrong count result");
    }
}
function checkCountExplain ( explain , nCounted ) { printjson ( explain ) ; var execStages = explain . executionStats . executionStages ; if ( "SINGLE_SHARD" == execStages . stage ) { var countStage = execStages . shards [ 0 ] . executionStages ; assert . eq ( countStage . stage , "COUNT" , "root stage on shard is not COUNT" ) ; assert . eq ( countStage . nCounted , nCounted , "wrong count result" ) ; } else { assert . eq ( execStages . stage , "COUNT" , "root stage is not COUNT" ) ; assert . eq ( execStages . nCounted , nCounted , "wrong count result" ) ; } }
Given explain output 'explain' at executionStats level verbosity,
 confirms that the root stage is COUNT and that the result of the
 count is equal to 'nCounted'.
Given explain output ' explain ' at executionStats level verbosity confirms that the root stage is COUNT and that the result of the count is equal to ' nCounted ' .
// If passed through mongos, then the root stage should be the mongos SINGLE_SHARD stage, // with COUNT as its child. If explaining directly on the shard, then COUNT is the root // stage.