Limitations
The aggregation pipeline can output results in the following three distinct ways:
- Inline as a document containing the result set
- In a collection
- Returning a cursor to the result set
Inline results are subject to a BSON
maximum document size of 16 MB, meaning that we should use this only if our final result is of a fixed size. An example of this would be outputting ObjectId
values of the top five most ordered items from an e-commerce site.
A contrary example to this would be outputting the top 1,000 most ordered items, along with the product information, including a description and various other fields of variable size.
Outputting results into a collection is the preferred solution if we want to perform further processing of the data. We can either output into a new collection or replace the contents of an existing collection. The aggregation output results will only be visible once the aggregation command succeeds; otherwise, it will...