Whatever everyone has posted as an answer holds true for inefficient use of index, but it still should come across as IXSCAN in explain plan, therefore I did a test.
db.sampledb.createIndex(
{
"DevIdent.ParametersExt. ID": 1,
"DevIdent.Parameters.Type": 1,
"MetaData.SessionName": 1
},
{
background: false,
name: "sample",
}
)
This is your command there is some space between DevIdent.ParametersExt. & ID, which is causing an issue but you still won't be able to create a new index without the space, gives duplicate error. Remove this index all together and create a new one without the space.
EDIT : Schoolkid mistake, remove the name part, you should be able to
create both the indexes, in the tree it is simply field name which is
a string being stored with respective BSON types, therefore with the
space and without it are two indexes separately.
db.sampledb.createIndex(
{
"DevIdent.ParametersExt.ID": 1,
"DevIdent.Parameters.Type": 1,
"MetaData.SessionName": 1
},
{
background: false,
name: "sample",
}
)
Try your aggregate command now, works for me.
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "test_content.test4",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"MetaData.SessionName" : {
"$eq" : "2021_02_09_13_31_03"
}
},
{
"DevIdent.ParametersExt.ID" : {
"$regex" : ".*22~44.*"
}
},
{
"DevIdent.Parameters.Type" : {
"$not" : {
"$eq" : "TYPICAL"
}
}
}
]
},
"optimizedPipeline" : true,
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"filter" : {
"DevIdent.ParametersExt.ID" : {
"$regex" : ".*22~44.*"
}
},
"keyPattern" : {
"DevIdent.ParametersExt.ID" : 1.0,
"DevIdent.Parameters.Type" : 1.0,
"MetaData.SessionName" : 1.0
},
"indexName" : "sample",
"isMultiKey" : false,
"multiKeyPaths" : {
"DevIdent.ParametersExt.ID" : [],
"DevIdent.Parameters.Type" : [],
"MetaData.SessionName" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"DevIdent.ParametersExt.ID" : [
"[\"\", {})",
"[/.*22~44.*/, /.*22~44.*/]"
],
"DevIdent.Parameters.Type" : [
"[MinKey, \"TYPICAL\")",
"(\"TYPICAL\", MaxKey]"
],
"MetaData.SessionName" : [
"[\"2021_02_09_13_31_03\", \"2021_02_09_13_31_03\"]"
]
}
}
},