<!-- llms-explorer concept facts · https://llms-explorer.com/tree/internalunpackbucket-explain-reading/ · pack 2026-10-22 · ~1139 tokens -->

# $_internalUnpackBucket explain reading

> Source-anchored research for $_internalUnpackBucket explain reading. Run status: COMPLETED.

Parent: [MongoDB Time-Series Query and Index Optimization](https://llms-explorer.com/tree/mongodb-time-series-query-and-index-optimization/) · 4 facets · 9 facts · page: https://llms-explorer.com/tree/internalunpackbucket-explain-reading/

## Structure and components

- Do not expect the literal $_internalUnpackBucket stage in every explain. MongoDB's manual says plan-tree structure differs between the classic and slot-based execution engines, and the current time-series README says an SBE-lowered plan uses an UNPACK_TS_BUCKET node instead. The README also distinguishes viewless 9.0+ collections from legacy system.buckets views, so check the server version and plan context before comparing output shapes. (high confidence) (verified as of 2026-10-22) — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)

## How it works

- MongoDB defines `executionStats.executionStages.nBucketsUnpacked` as the number of buckets unpacked to resolve a time-series operation. Treat it as a bucket count and compare it with unpack-stage `nReturned` and final results, because those counts can represent expanded measurements instead. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)

## Comparisons and alternatives

- Counts at different explain levels can describe different units. Percona's MongoDB 5.0 examples show bucket-level cursor counts differing from the measurement results returned by the normal query, while Guy Harrison's aggregation example shows the cursor and $_internalUnpackBucket stage returning different counts. Compare counters within their stage context instead of treating bucket counts as measurement counts. (medium confidence) — [source](https://www.percona.com/blog/mongodb-5-0-time-series-collections/)

## Facts and statements

- For time-series reads through the logical collection, MongoDB's translation adds `$_internalUnpackBucket` to the aggregation pipeline to expand stored bucket documents into measurement documents. Explain output can therefore show bucket-level cursor work followed by the unpack stage. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/timeseries/README.md)
- Read explain output as a stage tree. Inspect `$cursor.queryPlanner.winningPlan` and `$cursor.executionStats.executionStages` for the bucket access path, then inspect later aggregation `stages` for unpack and downstream work. A MongoDB 6.0.6 community example shows `COLLSCAN` against `system.buckets` inside `$cursor`, followed by `$_internalUnpackBucket` output. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Two dated explain examples illustrate the bucket-to-measurement expansion: Guy Harrison's MongoDB 5.0 helper output reported 409,219 cursor-returned buckets and 2,628,000 unpack-stage measurements (2022-02-14); a MongoDB 6.0.6 community output reported 26,583 cursor-returned bucket documents and 163,877 unpack-stage documents (2023-06-02). These are workload-specific historical values, not expected ratios. (medium confidence) (verified as of 2023-06-02) — [source](https://medium.com/mongodb-performance-tuning/mongodb-windows-function-and-time-series-performance-8d742addac34)
- Do not expect the literal `$_internalUnpackBucket` stage in every optimized pipeline: MongoDB's source README says some query rewrites remove it. MongoDB also warns that explain fields for internal use are not fully documented and output fields can change, so interpret the exact output for the deployed server version. (high confidence) (verified as of 2026-10-20) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/timeseries/README.md)
- For the classic explain shape of a legacy view-based time-series collection, the cursor reads backing system.buckets.<collection> documents, then $_internalUnpackBucket expands buckets into measurements; inspect the cursor plan separately from the pipeline stages after unpacking. (high confidence) (verified as of 2026-10-22) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/timeseries/README.md)
- MongoDB's manual says explain ignores the plan cache and does not cache its winning plan, so an explained winner is not necessarily the cached plan used by a live workload. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
