The FETCH stage retrieves complete documents after an earlier stage, commonly IXSCAN, identifies matching index keys. It appears in MongoDB execution plans between data-access stages and the final result stage. section 7.1.1
Read FETCH together with its input stage and execution statistics:
- IXSCAN locates matching keys in an index, then passes them to FETCH for document retrieval. section 7.1.1
- executionStats reports returned documents, execution time, keys examined, and documents examined, helping assess retrieval efficiency. section 7.1.1
- A query that the index fully supports can avoid unnecessary collection access; otherwise, FETCH reads documents for fields not covered by the index. section 7.2.1
Inspecting FETCH with explain()
Run db.movies.find({ "runtime": 100 }).explain("executionStats"). The winning plan shows FETCH above IXSCAN on runtime_1; the statistics show 719 matching documents, 719 keys examined, and 719 documents examined in the demonstrated query. section 7.2.1
Listing 7.2 Execution-plan output structure
{
"winningPlan": {
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"indexName": "yourField_1",
"keyPattern": {
"yourField": 1
},
"indexBounds": {
"yourField": [
"[\"value\", \"value\"]"
]
}
}
},
"executionStats": {
"nReturned": 1,
"executionTimeMillis": 3,
"totalKeysExamined": 1,
"totalDocsExamined": 1
}
}
Use the execution-plan structure to locate FETCH, inspect its IXSCAN input, and compare returned, examined, and timing metrics. section 7.1.1
