jstests/libs/analyze_plan.js
/**
 * Given explain output at executionStats level verbosity, confirms that the root stage is COUNT or
 * RECORD_STORE_FAST_COUNT and that the result of the count is equal to 'expectedCount'.
 */
Given explain output at executionStats level verbosity, confirms that the root stage is COUNT or
RECORD_STORE_FAST_COUNT and that the result of the count is equal to 'expectedCount'.
Given explain output at executionStats level verbosity confirms that the root stage is COUNT or RECORD_STORE_FAST_COUNT and that the result of the count is equal to ' expectedCount ' .
function assertExplainCount({explainResults, expectedCount}) {
    const execStages = explainResults.executionStats.executionStages;
    if ("SINGLE_SHARD" == execStages.stage || "SHARD_MERGE" == execStages.stage) {
        let totalCounted = 0;
        for (let shardExplain of execStages.shards) {
            const countStage = shardExplain.executionStages;
            assert(countStage.stage === "COUNT" || countStage.stage === "RECORD_STORE_FAST_COUNT",
                   `Root stage on shard is not COUNT or RECORD_STORE_FAST_COUNT. ` +
                       `The actual plan is: ${tojson(explainResults)}`);
            totalCounted += countStage.nCounted;
        }
        assert.eq(totalCounted,
                  expectedCount,
                  assert.eq(totalCounted, expectedCount, "wrong count result"));
    } else {
        assert(execStages.stage === "COUNT" || execStages.stage === "RECORD_STORE_FAST_COUNT",
               `Root stage on shard is not COUNT or RECORD_STORE_FAST_COUNT. ` +
                   `The actual plan is: ${tojson(explainResults)}`);
        assert.eq(
            execStages.nCounted,
            expectedCount,
            "Wrong count result. Actual: " + execStages.nCounted + "expected: " + expectedCount);
    }
}
function assertExplainCount ( { explainResults , expectedCount } ) { const execStages = explainResults . executionStats . executionStages ; if ( "SINGLE_SHARD" == execStages . stage || "SHARD_MERGE" == execStages . stage ) { let totalCounted = 0 ; for ( let shardExplain of execStages . shards ) { const countStage = shardExplain . executionStages ; assert ( countStage . stage === "COUNT" || countStage . stage === "RECORD_STORE_FAST_COUNT" , ` ` + ` ${ tojson ( explainResults ) } ` ) ; totalCounted += countStage . nCounted ; } assert . eq ( totalCounted , expectedCount , assert . eq ( totalCounted , expectedCount , "wrong count result" ) ) ; } else { assert ( execStages . stage === "COUNT" || execStages . stage === "RECORD_STORE_FAST_COUNT" , ` ` + ` ${ tojson ( explainResults ) } ` ) ; assert . eq ( execStages . nCounted , expectedCount , "Wrong count result. Actual: " + execStages . nCounted + "expected: " + expectedCount ) ; } }
Given explain output at executionStats level verbosity, confirms that the root stage is COUNT or
 RECORD_STORE_FAST_COUNT and that the result of the count is equal to 'expectedCount'.
Given explain output at executionStats level verbosity confirms that the root stage is COUNT or RECORD_STORE_FAST_COUNT and that the result of the count is equal to ' expectedCount ' .
// If passed through mongos, then the root stage should be the mongos SINGLE_SHARD stage or // SHARD_MERGE stages, with COUNT as the root stage on each shard. If explaining directly on the // shard, then COUNT is the root stage.