-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Query Planning
-
None
-
Query Optimization
-
Fully Compatible
-
ALL
-
v8.0, v7.0, v6.0
-
200
Consider the following example:
// tidx has index on {"array":1} > db.tidx.find() { "_id" : "A", "array" : [ [ 1 ], 1 ] } { "_id" : "B", "array" : [ true ] } { "_id" : "C", "array" : [ "b", true ] } { "_id" : "D", "array" : [ true, "c" ] } { "_id" : "E", "array" : [ [ 1 ], "d", true ] } { "_id" : "F", "array" : [ [ 1 ], "e", [ 1 ] ] } > db.tidx.aggregate({"$match": {"array": {"$gte": [[1]]}}}) // indexBounds: "array": [ [ [1] ], MaxKey ] { "_id" : "B", "array" : [ true ] } { "_id" : "D", "array" : [ true, "c" ] } { "_id" : "E", "array" : [ [ 1 ], "d", true ] } // ntidx does not have index on {"array": 1} > db.ntidx.find() { "_id" : "A", "array" : [ [ 1 ], 1 ] } { "_id" : "B", "array" : [ true ] } { "_id" : "C", "array" : [ "b", true ] } { "_id" : "D", "array" : [ true, "c" ] } { "_id" : "E", "array" : [ [ 1 ], "d", true ] } { "_id" : "F", "array" : [ [ 1 ], "e", [ 1 ] ] } > db.ntidx.aggregate({"$match": {"array": {"$gte": [[1]]}}}) { "_id" : "A", "array" : [ [ 1 ], 1 ] } { "_id" : "B", "array" : [ true ] } { "_id" : "D", "array" : [ true, "c" ] } { "_id" : "E", "array" : [ [ 1 ], "d", true ] } { "_id" : "F", "array" : [ [ 1 ], "e", [ 1 ] ] }
In the case with the index we are missing docs with _id A and F in the result set. These should match as per the comparison semantics defined in https://www.mongodb.com/docs/manual/reference/bson-type-comparison-order/#std-label-bson-types-comparison-order