- Aggregation >
- Aggregation Pipeline >
- Aggregation Pipeline Limits
Aggregation Pipeline Limits¶
On this page
Aggregation operations with the aggregate command have the following limitations.
Result Size Restrictions¶
Changed in version 2.6.
Starting in MongoDB 2.6, the aggregate command can return a cursor or store the results in a collection. When returning a cursor or storing the results in a collection, each document in the result set is subject to the BSON Document Size limit, currently 16 megabytes; if any single document that exceeds the BSON Document Size limit, the command will produce an error. The limit only applies to the returned documents; during the pipeline processing, the documents may exceed this size. The db.collection.aggregate() method returns a cursor by default starting in MongoDB 2.6
If you do not specify the cursor option or store the results in a collection, the aggregate command returns a single BSON document that contains a field with the result set. As such, the command will produce an error if the total size of the result set exceeds the BSON Document Size limit.
Earlier versions of the aggregate command can only return a single BSON document that contains the result set and will produce an error if the if the total size of the result set exceeds the BSON Document Size limit.
Memory Restrictions¶
Changed in version 2.6.
Pipeline stages have a limit of 100 megabytes of RAM. If a stage exceeds this limit, MongoDB will produce an error. To allow for the handling of large datasets, use the allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.
See also
$sort and Memory Restrictions and $group Operator and Memory.
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.