Performance with Views

When we query a view →

Do we first query the collection and then the views are computed for the results - OR
Are the views computed for the whole collection before we query them?.

Views are defined by aggregations - when you query a view your query is appended to that aggregation as a $match at the end and then the compound aggregation run. So in most cases the view is computed for the whole collection and then filtered by your query. If your view is simple enough then your query can be pushed up to the top but this only works for fairly simple views where adding your query at the top would have the same results.

1 Like