Hi there, I am a bit new to using Mongo and I am set up using mongo atlas to store a load of documents (~500,000) that all have an array of tags on them. The tag array usually has around 10 to 20 tags.
I am trying to query for documents based on several tags and sorted by a field.
The Index I have is set out like:
{ tags: 1, sort.profit: -1 }
and then the query is something like:
{
"filter": {
"tags": {
"$all": [
"profitability|profitable",
"currency-code|gbp",
"bids|no-bid",
"end-time|less-than-24-hours"
]
}
},
"sort": {
"sort.profit": -1
},
"limit": 50,
}
I’ve attached a profiler log with some bits redacted
{
"type": "command",
"ns": "",
"command": {
"find": "table",
"filter": {
"tags": {
"$all": [
"profitability|profitable",
"currency-code|gbp",
"bids|no-bid",
"end-time|less-than-24-hours"
]
}
},
"sort": {
"sort.profit": -1
},
"limit": 50,
"lsid": {
"id": {
"$binary": {
"base64": "",
"subType": ""
}
}
},
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"t": 0,
"i": 1
}
},
"signature": {
"hash": {
"$binary": {
"base64": "",
"subType": ""
}
},
"keyId":
}
},
"$db": ""
},
"planSummary": "IXSCAN { tags: 1, sort.profit: -1 }",
"keysExamined": 2310,
"docsExamined": 2310,
"fromMultiPlanner": true,
"cursorExhausted": true,
"numYields": 444,
"nreturned": 50,
"queryHash": "",
"planCacheKey": "",
"reslen": 342662,
"locks": {
"Global": {
"acquireCount": {
"r": 445
}
},
"Mutex": {
"acquireCount": {
"r": 1
}
}
},
"readConcern": {
"level": "local",
"provenance": "implicitDefault"
},
"storage": {
"data": {
"bytesRead": 698110513,
"timeReadingMicros": 7267966
},
"timeWaitingMicros": {
"cache": 28
}
},
"remote": "",
"protocol": "op_msg",
"durationMillis": 8175,
"v": "5.0.9"
}
I am seeing query times of more than 20 seconds in some cases. I assume I have set myself up incorrectly or I am trying to make mongo do something that it wasn’t designed for.