Perform aggregation on small set of documents

I have a query which returns 100 documents. While performing aggregation it considers all the documents . But I want to apply aggregation only on top 5 documents. Is there a way to achieve this?

Welcome to our community! :smiley:

How do you determine the top 5?

We have sorted based on geodistance.

Ok, so if you have a sort for that then you can change the size to 5.