Do views have optimizations (filter pushdown)?

I need a bit of complex grouping to get the correct result at the end of a pipeline.
So I have a match>sort>group>sort>group pipeline.

In a RDB if I create a view that basically omits the match at the beginning, I can then just work on this view and the match (where) is pushed down by the query planner.
Everything in the mongo docs seems to just say that it just executes the ‘view’ pipeline before my execution. So the first group would be ridiculously expensive if I don’t have a match even though at the end of the view I really just need a handful of docs.
Docs say that even in aggregation pipelines only the match and sort stages can be reordered but nothing after that.

Are they just tight lipped about under the hood optimizations or is that how it really works.
I know I can do on demand materializations but that is a lot more trouble.

1 Like