Hi everyone,
I am searching on more than 3 million records but fetching the data is very slow despite of using the indexes.
The problem here is $ne and $regex. While using other method like $eq, $in, $gt, $lt it is working fine and fetching the data very fast because it is using the correct index but while using the same query with $ne and $regex, it is taking more than 1 minute which is not feasible for my case as user wants the data within 3-4 seconds.
I have spent a lot of time in creating the proper index and by using the other methods it is also using the same index which I want but for $ne and $regex, it is behaving very different.
I am not able to figure out what to do to overcome this.
The problem with $ne and $regex is that it needs to scan a lot of data.
One scenario as an example :
user searches for email : {$ne:“abc@gmail.com”}, so in this case it must find the email not equal to “abc@gmail.com” so a lot of emails are there to scan so it is scanning so many docs which is taking more than 1 min so can you please suggest what to do?
Execution stats for such scenario :
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 773918.0,
"executionTimeMillis" : 8440.0,
"totalKeysExamined" : 773927.0,
"totalDocsExamined" : 773927.0,
}
"winningPlan" : {
"stage" : "PROJECTION_DEFAULT",
"transformBy" : {
"actor.user.email" : 1.0,
"actor.user.name" : 1.0,
"actor.user.uuid" : 1.0,
"time" : 1.0,
"_id" : 0.0
},
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"$and" : [
{
"actor.user.email" : {
"$not" : {
"$eq" : "aaron.barnett@example.com"
}
}
},
{
"customer.uuid" : {
"$eq" : "039e5026-be55-4ec6-a0ac-5ec82be0313b"
}
},
{
"sequr_code" : {
"$eq" : "SEQUR_ACCESS_GRANTED"
}
}
]
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"location.uuid" : 1.0,
"time" : -1.0
},
"indexName" : "location_uuid",
"isMultiKey" : false,
"multiKeyPaths" : {
"location.uuid" : [
],
"time" : [
]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2.0,
"direction" : "forward",
"indexBounds" : {
"location.uuid" : [
"[\"9eb44f41-3788-4b5b-b8f1-5f12b3956f69\", \"9eb44f41-3788-4b5b-b8f1-5f12b3956f69\"]"
],
"time" : [
"[new Date(1666411200000), new Date(1666238400000)]"
]
}
}
}
},
Thanks.