Hi, here is the explain with expr
:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "xxxx",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"status" : {
"$eq" : "DELETED"
}
},
{
"$expr" : {
"$lte" : [
"$createdDate",
{
"$subtract" : [
"$$NOW",
{
"$const" : 53646818400.0
}
]
}
]
}
}
]
},
"winningPlan" : {
"stage" : "FETCH",
"filter" : {
"$expr" : {
"$lte" : [
"$createdDate",
{
"$subtract" : [
"$$NOW",
{
"$const" : 53646818400.0
}
]
}
]
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"status" : 1
},
"indexName" : "status",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
]
}
}
},
"rejectedPlans" : [
{
"stage" : "FETCH",
"filter" : {
"$expr" : {
"$lte" : [
"$createdDate",
{
"$subtract" : [
"$$NOW",
{
"$const" : 53646818400.0
}
]
}
]
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"status" : 1,
"createdDate" : 1
},
"indexName" : "status_createdDate",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : [],
"createdDate" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
],
"createdDate" : [
"[MinKey, MaxKey]"
]
}
}
}
]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 0,
"executionTimeMillis" : 801,
"totalKeysExamined" : 15554,
"totalDocsExamined" : 15554,
"executionStages" : {
"stage" : "FETCH",
"filter" : {
"$expr" : {
"$lte" : [
"$createdDate",
{
"$subtract" : [
"$$NOW",
{
"$const" : 53646818400.0
}
]
}
]
}
},
"nReturned" : 0,
"executionTimeMillisEstimate" : 203,
"works" : 15556,
"advanced" : 0,
"needTime" : 15554,
"needYield" : 0,
"saveState" : 243,
"restoreState" : 243,
"isEOF" : 1,
"docsExamined" : 15554,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 15554,
"executionTimeMillisEstimate" : 0,
"works" : 15555,
"advanced" : 15554,
"needTime" : 0,
"needYield" : 0,
"saveState" : 243,
"restoreState" : 243,
"isEOF" : 1,
"keyPattern" : {
"status" : 1
},
"indexName" : "status",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
]
},
"keysExamined" : 15554,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0
}
}
},
"serverInfo" : {
"host" : "xxxxx",
"port" : 27017,
"version" : "4.2.18",
"gitVersion" : "f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016"
},
"ok" : 1.0,
"$clusterTime" : {
"clusterTime" : Timestamp(1642502477, 1),
"signature" : {
"hash" : { "$binary" : "xxxxx", "$type" : "00" },
"keyId" : NumberLong(xxxxx)
}
},
"operationTime" : Timestamp(1642502477, 1)
}
And here is with ISODate which uses index:
{
"createdDate": {"$lte": ISODate("2020-03-24T11:19:07.923Z")},
"status": "DELETED"
}
explain:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "xxxxxx",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"status" : {
"$eq" : "DELETED"
}
},
{
"createdDate" : {
"$lte" : ISODate("2020-03-24T11:19:07.923Z")
}
}
]
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"status" : 1,
"createdDate" : 1
},
"indexName" : "status_createdDate",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : [],
"createdDate" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
],
"createdDate" : [
"(true, new Date(1585048747923)]"
]
}
}
},
"rejectedPlans" : [
{
"stage" : "FETCH",
"filter" : {
"createdDate" : {
"$lte" : ISODate("2020-03-24T11:19:07.923Z")
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"status" : 1
},
"indexName" : "status",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
]
}
}
}
]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 0,
"executionTimeMillis" : 0,
"totalKeysExamined" : 0,
"totalDocsExamined" : 0,
"executionStages" : {
"stage" : "FETCH",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 2,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"docsExamined" : 0,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 0,
"executionTimeMillisEstimate" : 0,
"works" : 1,
"advanced" : 0,
"needTime" : 0,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"keyPattern" : {
"status" : 1,
"createdDate" : 1
},
"indexName" : "status_createdDate",
"isMultiKey" : false,
"multiKeyPaths" : {
"status" : [],
"createdDate" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"status" : [
"[\"DELETED\", \"DELETED\"]"
],
"createdDate" : [
"(true, new Date(1585048747923)]"
]
},
"keysExamined" : 0,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0
}
}
},
"serverInfo" : {
"host" : "xxxxxxx",
"port" : 27017,
"version" : "4.2.18",
"gitVersion" : "f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016"
},
"ok" : 1.0,
"$clusterTime" : {
"clusterTime" : Timestamp(1642502937, 1),
"signature" : {
"hash" : { "$binary" : "xxxxxx", "$type" : "00" },
"keyId" : NumberLong(xxxxxx)
}
},
"operationTime" : Timestamp(1642502937, 1)
}