I have two indexes {timestamp:1}
and {code:1,timestamp:1}
timestamp
is date, while code
is string.
code
contains a string like the ones below:
1_ABC_1
1_ABC_2
1_PQR_1
1_XYZ_1
Following is my match stage:
{
"code": {
"$regex": "WMS"
},
"timestamp": {
"$gte": {
"$date": 1596220200000
},
"$lte": {
"$date": 1597429799999
}
}
}
Yet, the winning plan ends up being the following:
{
"stage" : "FETCH",
"filter" : {
"device" : {
"$regex" : "ABC"
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"timestamp" : 1
},
"indexName" : "timestamp_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"timestamp" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"timestamp" : [
"[{ $date: 1596220200000.0 }, { $date: 1597429799999.0 }]"
]
}
}
}