[SERVER-61839] $elemMatch w/ positional $ project SBE bug Created: 01/Dec/21  Updated: 29/Oct/23  Resolved: 10/Dec/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.2.0, 5.1.0
Fix Version/s: 5.3.0, 5.1.2, 5.2.0-rc1

Type: Bug Priority: Critical - P2
Reporter: James Wahlin Assignee: Drew Paroski
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.2
Steps To Reproduce:

(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();
}());

Sprint: QE 2021-12-13
Participants:

 Description   

In the above reproduction, the asserts pass with SBE disabled. The first assert in firstBatch.length fails when SBE is enabled.



 Comments   
Comment by Githook User [ 14/Dec/21 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-61839 Fix SBE implementation of $exists and $type when a positional projection is used

(cherry picked from commit 8d4e810c89b771ded201390990a527a9a8799d2f)
(cherry picked from commit 1dec4dba560a2ee2bf518ec44cacf4813de88fda)
Branch: v5.1
https://github.com/mongodb/mongo/commit/4773f863721e1a726c7fdbd837a43003cd555629

Comment by Githook User [ 10/Dec/21 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-61839 Fix SBE implementation of $exists and $type when a positional projection is used

(cherry picked from commit 8d4e810c89b771ded201390990a527a9a8799d2f)
Branch: v5.2
https://github.com/mongodb/mongo/commit/1dec4dba560a2ee2bf518ec44cacf4813de88fda

Comment by Githook User [ 10/Dec/21 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-61839 Fix SBE implementation of $exists and $type when a positional projection is used
Branch: master
https://github.com/mongodb/mongo/commit/8d4e810c89b771ded201390990a527a9a8799d2f

Comment by James Wahlin [ 02/Dec/21 ]

I posted a simplified reproduction to this ticket. Worth noting is both the positional projection and the $exists clause were needed to repro. 

Generated at Thu Feb 08 05:53:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.