M201 - Chapter 4 - Aggregation Performance - $limit to reduce document size?

In Chapter 4, the lecture on Aggregation Performance (namely the Memory Constraints section) gets into the 16MB limit on documents, and suggests using both $limit and $project to reduce document size.

$project I understand, but how does $limit reduce document size? $limit is for reducing the size of the total document set, no?

Hi @Brian_McQueen_11582,

You are right!!
The $limit will have no effect on the content of the document. It will just keep a check on number of documents passing through the pipeline.
However the usage of $limit will keep a check on the memory usage in the pipeline. For example if we want to maintain top-n result in our aggregation pipeline, we can coalesce the $limit into $sort and this will reduce the memory usage in the process of transforming the data.

I hope it answers your question.

Please feel free to reach out if you have any additional questions.