I'm using mongoDB with Parse Server and experiencing a COLLSCAN even if I have an index. I'm accessing the _Session table and finding the correct "_session_token". Js code:
let query = new Parse.Query('_Session');
query.equalTo('sessionToken', userAuthToken);
query.include('user');
var session = await query.first({ useMasterKey: true });
Index: db.Session.createIndex( {"_session_token": 1} );
DocumentDB profiling result:
{
"op": "query",
"ts": 1595363106950,
"ns": "production._Session",
"command": {
"find": "_Session",
"filter": {
"_session_token": "r:03c7703fcb856a97e475d1a306ea4f3b"
},
"sort": {},
"projection": {},
"limit": 1,
"returnKey": false,
"showRecordId": false,
"$db": "production",
"$readPreference": {
"mode": "secondaryPreferred"
}
},
"cursorExhausted": true,
"nreturned": 1,
"responseLength": 307,
"protocol": "op_query",
"millis": 952,
"planSummary": "COLLSCAN",
"execStats": {
"stage": "SUBSCAN",
"nReturned": "1",
"executionTimeMillisEstimate": "902.042",
"inputStage": {
"stage": "LIMIT_SKIP",
"nReturned": "1",
"executionTimeMillisEstimate": "902.029",
"inputStage": {
"stage": "COLLSCAN",
"nReturned": "1",
"executionTimeMillisEstimate": "902.026"
}
}
},
"client": "",
"user": ""
}
What should I do? If I execute db.Session.find({_session_token: "xpto"})
the index is used, but if I use Parse this happens.
Create the index using:
db.getCollection('_Session').createIndex( {"_session_token": 1} );