-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
-
ALL
-
Query 12 (04/04/16), Query 13 (04/22/16)
db.pos3.aggregate([{$unwind:{path:"$likes",preserveNullAndEmptyArrays:true, includeArrayIndex:"index"}},{$match:{person:"Asya",index:0}}],{explain:true}) { "waitedMS" : NumberLong(0), "stages" : [ { "$cursor" : { "query" : { "person" : "Asya", "index" : 0 }, "queryPlanner" : { "plannerVersion" : 1, "namespace" : "test.pos3", "indexFilterSet" : false, "parsedQuery" : { "$and" : [ { "index" : { "$eq" : 0 } }, { "person" : { "$eq" : "Asya" } } ] }, "winningPlan" : { "stage" : "FETCH", "filter" : { "index" : { "$eq" : 0 } }, "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "person" : 1, "likes.cat" : 1, "likes.val" : 1 }, "indexName" : "person_1_likes.cat_1_likes.val_1", "isMultiKey" : true, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 1, "direction" : "forward", "indexBounds" : { "person" : [ "[\"Asya\", \"Asya\"]" ], "likes.cat" : [ "[MinKey, MaxKey]" ], "likes.val" : [ "[MinKey, MaxKey]" ] } } }, "rejectedPlans" : [ ] } } }, { "$unwind" : { "path" : "$likes", "preserveNullAndEmptyArrays" : true, "includeArrayIndex" : "index" } } ], "ok" : 1 }
Note that "index" field comparison was moved ahead of $unwind where it might be matching a different field than generated index from $unwind, or if no such field exists, it rejects documents which should be kept.
Need to include match on generated index field in exceptions to switching match components around.
- is related to
-
SERVER-20506 Conditionally order $match with $unwind
- Closed