In MongoDB, an on-demand materialized view is the stored result of an aggregation pipeline. The pipeline writes its result to disk with $merge or $out, so a read retrieves precalculated data instead of recalculating the pipeline. This can improve read performance, especially when the pipeline is complex or aggregates a large volume of data. section 2.6.3
The trade-off is freshness. A standard view runs its pipeline when queried and reflects the underlying data at that time; an on-demand materialized view does not update automatically. When source data changes, rerun the aggregation pipeline to write updated results to the stored collection. section 2.6.3 section 2.7
Choosing between live and stored results
A view that filters a routes collection with $match can provide a convenient live subset. If repeatedly calculating a pipeline becomes costly, storing its result as an on-demand materialized view can speed reads—but the stored result needs an explicit refresh after the routes change. section 2.6.3




