I created a local cluster and have being trying to learn how to do simple searches and have come across an issue with indexes not being used. I have a collection with simple docs in the form
{
“_id”: {
“$oid”: “67ad17c03e1c2b419bedbded”
},
“AAUID”: 1877,
“BIID”: 250,
“BID”: 813
}
I also have an index called AAUID which should cover “AAUID”
getIndexes() returns:
[
{
v: 2,
key: { _id: 1 },
name: ‘id’,
unique: true,
clustered: true
},
{ v: 2, key: { AAUID: 1 }, name: ‘AAUID’ }
]
But when I query using
find({AAUID:123}).explain()
I see “COLLSCAN”
{
“isCached”: false,
“stage”: “COLLSCAN”,
“filter”: {
“AAUID”: {
“$eq”: 123
}
},
“nReturned”: 2493,
“executionTimeMillisEstimate”: 4689,
“works”: 5000001,
“advanced”: 2493,
“needTime”: 4997507,
“needYield”: 0,
“saveState”: 322,
“restoreState”: 322,
“isEOF”: 1,
“direction”: “forward”,
“docsExamined”: 5000000
}
And the Explain Plan in Compass says “No index available for this query.”
Query returns in a few seconds which isn’t bad but I will have 300million docs in the future and at that rate it will be unusable.