Trying to figure this out, running a simple query like this
.find()
.sort({ _id: 1 })
.limit(100)
.hint({ _id: 1 }).explain("executionStats");
And it's doing a full scan everytime
executionTimeMillis: 329.892,
executionStartAtTimeMillis: 0.038,
totalDocsExamined: 204773,
totalKeysExamined: 204773,
But when I run against a real mongo instance it uses the _id index to sort
executionTimeMillis: 0,
totalKeysExamined: 100,
totalDocsExamined: 100,
My collection in azure is not sharded or anything like that, is this just a limitation of the Cosmos Mongo emulation or is something up with my indexes. If so is there any documentation explaining that?
Edit: Here is the full explain results, I've tried with and without a filter just to see if it made a difference
{
explainVersion: 2,
command: "db.runCommand({explain: { 'find' : 'Collection', 'filter' : { }, 'sort' : { '_id' : 1 }, 'limit' : 100 }})",
explainCommandPlanningTimeMillis: 0.198,
explainCommandExecTimeMillis: 222.434,
queryPlanner: {
namespace: 'Database.Collection',
winningPlan: {
stage: 'LIMIT',
estimatedTotalKeysExamined: 100,
inputStage: {
stage: 'COLLSCAN',
estimatedTotalKeysExamined: 170402,
inputStage: {
stage: 'SORT',
sortKeysCount: 1,
estimatedTotalKeysExamined: 85201,
inputStage: {
stage: 'COLLSCAN',
estimatedTotalKeysExamined: 85201
}
}
}
}
},
executionStats: {
nReturned: 100,
executionTimeMillis: 222.376,
executionStartAtTimeMillis: 192.863,
totalDocsExamined: 100,
totalKeysExamined: 100,
executionStages: {
stage: 'LIMIT',
nReturned: 100,
executionTimeMillis: 222.376,
executionStartAtTimeMillis: 192.863,
totalDocsExamined: 100,
totalKeysExamined: 100,
numBlocksFromCache: 29381,
numBlocksFromDisk: 11142,
inputStage: {
stage: 'COLLSCAN',
nReturned: 100,
executionTimeMillis: 222.365,
executionStartAtTimeMillis: 192.861,
totalDocsExamined: 100,
totalKeysExamined: 100,
numBlocksFromCache: 29381,
numBlocksFromDisk: 11142,
parallelWorkers: 2,
inputStage: {
stage: 'SORT',
nReturned: 70,
executionTimeMillis: 171.279,
executionStartAtTimeMillis: 171.262,
totalDocsExamined: 70,
totalKeysExamined: 70,
sortMethod: 'top-N heapsort',
totalDataSizeSortedBytesEstimate: 189,
numBlocksFromCache: 29381,
numBlocksFromDisk: 11142,
inputStage: {
stage: 'COLLSCAN',
nReturned: 68258,
executionTimeMillis: 121.96000000000001,
executionStartAtTimeMillis: 0.056,
totalDocsExamined: 68258,
totalKeysExamined: 68258,
numBlocksFromCache: 29289,
numBlocksFromDisk: 11142
}
}
}
}
},
ok: 1
}