Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
-
ALL
Description
I might miss something but when I create compound index for nested array of documents, when I filter by fields from those index, only one of them is filtered inside INDEX_SCAN stage, and another field is filtered in FETCH stage
Sample script:
db.test.drop()
|
for(var i = 0; i < 100; i++){ |
db.test.insert({units: [{jobs: [{jobType: i % 3, status: i % 10 }]}]}) |
}
|
db.test.createIndex({"units.jobs.status": 1, "units.jobs.jobType": 1}) |
db.test
|
.find({ "units" : { "$elemMatch" : { "jobs" : { "$elemMatch" : { "jobType" : 0, "status" : 3 } } } }}) |
.explain('executionStats') |
Last query end up with following INDEX_SCAN:
"indexBounds" : { "indexBounds" :
{ "units.jobs.status" : [ "[3.0, 3.0]" ], "units.jobs.jobType" : [ "[MinKey, MaxKey]" ] },
and result set is filtered with FETCH phase.
Is this expected behavious and if so, what is possible workaround?
Thanks in advance