jstests/core/projection_semantics.js
// Tests that this remains true if indexes are added, or if we use aggregation instead of find.
Tests that this remains true if indexes are added, or if we use aggregation instead of find.
Tests that this remains true if indexes are added or if we use aggregation instead of find .
function testInputOutput({input, projection, expectedOutput, interestingIndexes = []}) {
    coll.drop();
    assert.commandWorked(coll.insert(input));
    assert.docEq(coll.findOne({}, projection), expectedOutput);
    for (let indexSpec of interestingIndexes) {
        assert.commandWorked(coll.createIndex(indexSpec));
        assert.docEq(coll.find({}, projection).hint(indexSpec).toArray()[0], expectedOutput);
        assert.commandWorked(coll.dropIndex(indexSpec));
    }
    assert.docEq(coll.aggregate([{$project: projection}]).toArray()[0], expectedOutput);
}
function testInputOutput ( { input , projection , expectedOutput , interestingIndexes = [ ] } ) { coll . drop ( ) ; assert . commandWorked ( coll . insert ( input ) ) ; assert . docEq ( coll . findOne ( { } , projection ) , expectedOutput ) ; for ( let indexSpec of interestingIndexes ) { assert . commandWorked ( coll . createIndex ( indexSpec ) ) ; assert . docEq ( coll . find ( { } , projection ) . hint ( indexSpec ) . toArray ( ) [ 0 ] , expectedOutput ) ; assert . commandWorked ( coll . dropIndex ( indexSpec ) ) ; } assert . docEq ( coll . aggregate ( [ { $project : projection } ] ) . toArray ( ) [ 0 ] , expectedOutput ) ; }
Tests that this remains true if indexes are added, or if we use aggregation instead of find.
Tests that this remains true if indexes are added or if we use aggregation instead of find .