|
Looks like $expr won't use sparse indexes either (they are similar to partial indexes I guess).
With sparse index on fid
db.foreign.explain().find({$expr:{$eq:["$fid",100]}})
|
{
|
"explainVersion" : "2",
|
"queryPlanner" : {
|
"namespace" : "test.foreign",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"$and" : [
|
{
|
"$expr" : {
|
"$eq" : [
|
"$fid",
|
{
|
"$const" : 100
|
}
|
]
|
}
|
},
|
{
|
"fid" : {
|
"$_internalExprEq" : 100
|
}
|
}
|
]
|
},
|
"queryHash" : "E854ED70",
|
"planCacheKey" : "E5C24B58",
|
"maxIndexedOrSolutionsReached" : false,
|
"maxIndexedAndSolutionsReached" : false,
|
"maxScansToExplodeReached" : false,
|
"winningPlan" : {
|
"queryPlan" : {
|
"stage" : "COLLSCAN",
|
"planNodeId" : 1,
|
"filter" : {
|
"$and" : [
|
{
|
"$expr" : {
|
"$eq" : [
|
"$fid",
|
{
|
"$const" : 100
|
}
|
]
|
}
|
},
|
{
|
"fid" : {
|
"$_internalExprEq" : 100
|
}
|
}
|
]
|
},
|
"direction" : "forward"
|
}, // etc.
|
|
|
Confirmed (with 4.1.13) that this has to do with $expr syntax specifically as using the matcher syntax I see:
db.getCollection('contacts').find({name:"A"}).explain()
|
{
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "test.contacts",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"name" : {
|
"$eq" : "A"
|
}
|
},
|
"queryHash" : "01AEE5EC",
|
"planCacheKey" : "4C5AEA2C",
|
"winningPlan" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"name" : 1,
|
"email" : 1
|
},
|
"indexName" : "name_1_email_1",
|
"isMultiKey" : false,
|
"multiKeyPaths" : {
|
"name" : [ ],
|
"email" : [ ]
|
},
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : true,
|
"indexVersion" : 2,
|
"direction" : "forward",
|
"indexBounds" : {
|
"name" : [
|
"[\"A\", \"A\"]"
|
],
|
"email" : [
|
"[MinKey, MaxKey]"
|
]
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
},
|
"serverInfo" : {
|
"host" : "asyas-macbook-pro-3.local",
|
"port" : 41130,
|
"version" : "4.1.13",
|
"gitVersion" : "441714bc4c70699950f3ac51a5cac41dcd413eaa"
|
},
|
"ok" : 1
|
}
|
|