Hello,
I checked all over but I cant seem to find a solution.
I want to run a simple $gte operator on a date field. The field is indexed. For some reason, It looks like the IXSCAN phase is returning of all the results to the parent node.
mongodb version 4.4.13
the query is:
const pipeline = [
{
"$match": {
"$expr": {
"$and": [
{ $gte: ["$timestamp", new Date("2022-04-23T00:00:00.000Z")] }
]
}
}
}
const res = await this._demandSupplyTransactionModel.aggregate(pipeline,
{
hint: `timestamp`
}
).allowDiskUse(true).exec();
and the run results:
{
"executionSuccess": true,
"nReturned": 168940,
"executionTimeMillis": 16335,
"totalKeysExamined": 6366938,
"totalDocsExamined": 6366938,
"executionStages": {
"stage": "FETCH",
"filter": {
"$expr": {
"$and": [
{
"$gte": [
"$timestamp",
{
"$const": "2022-04-23T00:00:00.000Z"
}
]
}
]
}
},
"nReturned": 168940,
"executionTimeMillisEstimate": 13576,
"works": 6366939,
"advanced": 168940,
"needTime": 6197998,
"needYield": 0,
"saveState": 6430,
"restoreState": 6430,
"isEOF": 1,
"docsExamined": 6366938,
"alreadyHasObj": 0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 6366938,
"executionTimeMillisEstimate": 4838,
"works": 6366939,
"advanced": 6366938,
"needTime": 0,
"needYield": 0,
"saveState": 6430,
"restoreState": 6430,
"isEOF": 1,
"keyPattern": {
"timestamp": 1
},
"indexName": "timestamp",
"isMultiKey": false,
"multiKeyPaths": {
"timestamp": []
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"timestamp": [
"[MinKey, MaxKey]"
]
},
"keysExamined": 6366938,
"seeks": 1,
"dupsTested": 0,
"dupsDropped": 0
}
},
"allPlansExecution": []
}