When should consider using aggregation framework and not query language?

After learning chapter 2: cursor-like stages, there are the same operators in the query language as in the aggregation framework, the same applies for find() and $match.
So which usecase should we use the aggregation framework and not the query language?

1 Like

Hi @nattawan,

Great Question!!

When you need to fetch some documents based on some query criteria stored in a collection, in that case find() operation is the best choice.
However, when we need to fetch a large number of documents, group/process them and return a combined result. Then aggregation is the best option to do so.

Aggregation operation performs operations using the aggregation pipeline. The pipeline allows users to process data from a collection or other source with a sequence of stage-based manipulations.

You can refer to the following article for detailed description of usage of Aggregation:

Please let know, if you have any questions.


Good article for when to apply aggregation . Thanks. I got my answer.

1 Like