Hello Carl
Thanks for looking into this
So here is my index
db.getCollection("my-collection").createIndex(
{
type: 1,
'details.category': 1,
'details.description': 1,
'details,overview': 1,
'details.reference': 1
})
And here is my first query
db.getCollection("my-collection").find({
type: "core.module.safetyplan",
}).explain("executionStats")
Here is the executionStats
{
"executionSuccess": true,
"nReturned": 302.0,
"executionTimeMillis": 0.0,
"totalKeysExamined": 302.0,
"totalDocsExamined": 302.0,
"executionStages": {
"stage": "FETCH",
"nReturned": 302.0,
"executionTimeMillisEstimate": 1.0,
"works": 303.0,
"advanced": 302.0,
"needTime": 0.0,
"needYield": 0.0,
"saveState": 0.0,
"restoreState": 0.0,
"isEOF": 1.0,
"docsExamined": 302.0,
"alreadyHasObj": 0.0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 302.0,
"executionTimeMillisEstimate": 1.0,
"works": 303.0,
"advanced": 302.0,
"needTime": 0.0,
"needYield": 0.0,
"saveState": 0.0,
"restoreState": 0.0,
"isEOF": 1.0,
"keyPattern": {
"type": 1.0,
"details.category": 1.0,
"details.description": 1.0,
"details,overview": 1.0,
"details.reference": 1.0
},
"indexName": "type_1_details.category_1_details.description_1_details,overview_1_details.reference_1",
"isMultiKey": false,
"multiKeyPaths": {
"type": [],
"details.category": [],
"details.description": [],
"details,overview": [],
"details.reference": []
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"type": [
"[\"core.module.safetyplan\", \"core.module.safetyplan\"]"
],
"details.category": [
"[MinKey, MaxKey]"
],
"details.description": [
"[MinKey, MaxKey]"
],
"details,overview": [
"[MinKey, MaxKey]"
],
"details.reference": [
"[MinKey, MaxKey]"
]
},
"keysExamined": 302.0,
"seeks": 1.0,
"dupsTested": 0.0,
"dupsDropped": 0.0
}
}
}
And when I add another field on my query
db.getCollection("my-collection").find({
type: "core.module.safetyplan",
'details.description': "This is long description."
}).explain("executionStats")
And here is the executionStats
of my second query
{
"executionSuccess": true,
"nReturned": 21.0,
"executionTimeMillis": 0.0,
"totalKeysExamined": 26.0,
"totalDocsExamined": 21.0,
"executionStages": {
"stage": "FETCH",
"nReturned": 21.0,
"executionTimeMillisEstimate": 0.0,
"works": 26.0,
"advanced": 21.0,
"needTime": 4.0,
"needYield": 0.0,
"saveState": 0.0,
"restoreState": 0.0,
"isEOF": 1.0,
"docsExamined": 21.0,
"alreadyHasObj": 0.0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 21.0,
"executionTimeMillisEstimate": 0.0,
"works": 26.0,
"advanced": 21.0,
"needTime": 4.0,
"needYield": 0.0,
"saveState": 0.0,
"restoreState": 0.0,
"isEOF": 1.0,
"keyPattern": {
"type": 1.0,
"details.category": 1.0,
"details.description": 1.0,
"details,overview": 1.0,
"details.reference": 1.0
},
"indexName": "type_1_details.category_1_details.description_1_details,overview_1_details.reference_1",
"isMultiKey": false,
"multiKeyPaths": {
"type": [],
"details.category": [],
"details.description": [],
"details,overview": [],
"details.reference": []
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"type": [
"[\"core.module.safetyplan\", \"core.module.safetyplan\"]"
],
"details.category": [
"[MinKey, MaxKey]"
],
"details.description": [
"[\"This is long description.\", \"This is long description.\"]"
],
"details,overview": [
"[MinKey, MaxKey]"
],
"details.reference": [
"[MinKey, MaxKey]"
]
},
"keysExamined": 26.0,
"seeks": 5.0,
"dupsTested": 0.0,
"dupsDropped": 0.0
}
}
}
As you can see the keysExamined decreased