jstests/aggregation/optimize_away_pipeline.js
// layer. The test will verify that this pushdown is reflected in explain output.
layer. The test will verify that this pushdown is reflected in explain output.
layer . The test will verify that this pushdown is reflected in explain output .
function assertPipelineUsesAggregation({
    pipeline = [],
    pipelineOptions = {},
    expectedStages = null,
    expectedResult = null,
    preserveResultOrder = false,
    optimizedAwayStages = null
} = {}) {
    const explainOutput = coll.explain().aggregate(pipeline, pipelineOptions);
    assert(isAggregationPlan(explainOutput), explainOutput);
    assert(!isQueryPlan(explainOutput), explainOutput);
    if (optimizedAwayStages) {
        for (let stage of optimizedAwayStages) {
            assert(!aggPlanHasStage(explainOutput, stage), explainOutput);
        }
    }
    let cursor = getAggPlanStage(explainOutput, "$cursor");
    if (cursor) {
        cursor = cursor.$cursor;
    } else {
        cursor = getAggPlanStage(explainOutput, "$geoNearCursor").$geoNearCursor;
    }
    assert(cursor, explainOutput);
    assert(cursor.queryPlanner.optimizedPipeline === undefined, explainOutput);
    if (expectedStages) {
        for (let expectedStage of expectedStages) {
            assert(aggPlanHasStage(explainOutput, expectedStage), explainOutput);
        }
    }
    if (expectedResult) {
        const actualResult = coll.aggregate(pipeline, pipelineOptions).toArray();
        if (preserveResultOrder) {
            assert.docEq(actualResult, expectedResult);
        } else {
            assert.sameMembers(actualResult, expectedResult);
        }
    }
    return explainOutput;
}
function assertPipelineUsesAggregation ( { pipeline = [ ] , pipelineOptions = { } , expectedStages = null , expectedResult = null , preserveResultOrder = false , optimizedAwayStages = null } = { } ) { const explainOutput = coll . explain ( ) . aggregate ( pipeline , pipelineOptions ) ; assert ( isAggregationPlan ( explainOutput ) , explainOutput ) ; assert ( ! isQueryPlan ( explainOutput ) , explainOutput ) ; if ( optimizedAwayStages ) { for ( let stage of optimizedAwayStages ) { assert ( ! aggPlanHasStage ( explainOutput , stage ) , explainOutput ) ; } } let cursor = getAggPlanStage ( explainOutput , "$cursor" ) ; if ( cursor ) { cursor = cursor . $cursor ; } else { cursor = getAggPlanStage ( explainOutput , "$geoNearCursor" ) . $geoNearCursor ; } assert ( cursor , explainOutput ) ; assert ( cursor . queryPlanner . optimizedPipeline === undefined , explainOutput ) ; if ( expectedStages ) { for ( let expectedStage of expectedStages ) { assert ( aggPlanHasStage ( explainOutput , expectedStage ) , explainOutput ) ; } } if ( expectedResult ) { const actualResult = coll . aggregate ( pipeline , pipelineOptions ) . toArray ( ) ; if ( preserveResultOrder ) { assert . docEq ( actualResult , expectedResult ) ; } else { assert . sameMembers ( actualResult , expectedResult ) ; } } return explainOutput ; }
layer.
layer .