(function() {
'use strict';
function runTest() {
db.test.drop();
db.test.insert({ _id: 1, "states": [{x: 1, y: 1}, {x: 2, y: 2}]});
let result = db.test.runCommand({find: "test", filter: {_id: 1 , states: {"$elemMatch": {x: 1, "y": {"$exists": true}}}}, projection: {"states.$": 1 }, limit: 1, singleBatch: true});
assert.eq(result.cursor.firstBatch.length, 1, "firstBatch is empty");
assert.eq(result.cursor.firstBatch[0].states.length, 1, "states array is empty");
assert.eq(result.cursor.firstBatch[0].states[0].x, 1, "unexpected 'states' document returned");
}
printjson("Run test with SBE disabled");
assert.commandWorked(
db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: true}));
runTest();
printjson("Run test with SBE enabled");
assert.commandWorked(
db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: false}));
runTest();
}());