BugZero found this defect 59 days ago.
Data sources
All data on this page is proprietary to BugZero® or gathered from public sources
3/21/2024
MongoDB Server
No affected releases provided.
No fixed releases provided.
The following aggregation pipeline produces incorrect result when run with disabled optimization: db.xxx.aggregate([ {$match: {a: {$ne: 2}}}, {$match: {b: {$exists: false}}}, {"$count" : "a"} ]); The incorrect result is observed both with classic and sbe engines. If we remove the $count stage, the pipeline produces correct result. The pipeline works correctly with optimization and with a collection scan if the index does not exist. The execution stats on the second $match expression `{$match: {b: {$exists: false}}}` shows 1 returned result in the pipeline without $count, and 0 nReturned in the other case. See the full explain in the attachments. // no $count: {"$match" : { "b" : { "$not" : { "$exists" : true } } }, "nReturned" : NumberLong(1), "executionTimeMillisEstimate" : NumberLong(1) }, ... // with $count {"$match" : { "b" : { "$not" : { "$exists" : true } } }, "nReturned" : NumberLong(0), "executionTimeMillisEstimate" : NumberLong(1) }, ...
db.xxx.insertMany([ {_id: 1, a: 1, b: null, c: 3}, {_id: 2, a: 2, b: null, c: 4}, {_id: 3, a: 2, b: 2, c: 3}, {_id: 4, a: 2, c: 5}, {_id: 5, a: 3, b: null, c: 6}, {_id: 6, a: 4, c: 7}]); db.xxx.createIndex({a:1, b:1}); db.adminCommand({configureFailPoint: 'disablePipelineOptimization', mode: 'alwaysOn'}); db.xxx.aggregate([ {$match: {a: {$ne: 2}}}, {$match: {b: {$exists: false}}}, {"$count" : "a"} ]);