I’m receiving this MongoDB alert: Query Targeting: Scanned Objects / Returned has exceeded 1000.
Although I believe I’ve indexed the necessary fields for my query, it seems that the issue lies in the ratio of scanned documents to returned documents being too high.
Attached is an example query that’s triggering this alert:
"filter": {
"$expr": {
"$or": [
{
"$and": [
{
"$eq": [
"$status",
"available"
]
},
{
"$lt": [
1716655410125,
{
"$subtract": [
"$rentData.expirationOffer",
86400000
]
}
]
},
{
"$gt": [
{
"$size": {
"$filter": {
"input": "$rentData.rentedValue",
"as": "item",
"cond": {
"$regexMatch": {
"input": "$$item.unit",
"regex": {
"$regularExpression": {
"pattern": "^7ffd549a929ce890e1cf1fcfd95ec2170d53dafdaa27147a38ff5e4d",
"options": ""
}
},
"options": "i"
}
}
}
}
},
0
]
}
]
},
{
"$and": [
{
"$eq": [
"$status",
"active"
]
},
{
"$gt": [
1716655410125,
"$rentData.deadlineDate"
]
},
{
"$lt": [
1716655410125,
{
"$subtract": [
"$rentData.expirationOffer",
86400000
]
}
]
},
{
"$gt": [
{
"$size": {
"$filter": {
"input": "$rentData.rentedValue",
"as": "item",
"cond": {
"$regexMatch": {
"input": "$$item.unit",
"regex": {
"$regularExpression": {
"pattern": "^7ffd549a929ce890e1cf1fcfd95ec2170d53dafdaa27147a38ff5e4d",
"options": ""
}
},
"options": "i"
}
}
}
}
},
0
]
}
]
}
]
}
},
"sort": {
"_id": -1
},
"skip": 0,
"limit": 20,
The indexed fields used in this query are: status, rentData.expirationOffer, and a compound index on status and rentData.deadlineDate.
Could you provide guidance on resolving this error?