MongoDB : Sort exceeded memory limit of 104857600 bytes
By:Roy.LiuLast updated:2019-08-17
Performs a large sort operation (Aggregation) in a collection, and hits the following error message :
MongoDB Console
> db.bigdata.aggregate( {$group : {_id : "$range", total : { $sum : 1 }}}, {$sort : {total : -1}} ); #... aggregate failed at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) #... Error: command failed: { "errmsg" : "exception: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.", "code" : 16819, "ok" : 0
P.S Tested with MongoDB 3.0.6
Solution
Changed in version 2.6 – Read this Memory Restrictions
In MongoDB, the in-memory sorting have a limit of 100M, to perform a large sort, you need enable allowDiskUse option to write data to a temporary files for sorting.
In MongoDB, the in-memory sorting have a limit of 100M, to perform a large sort, you need enable allowDiskUse option to write data to a temporary files for sorting.
To fix it, enable the allowDiskUse option in your query :
db.bigdata.aggregate( {$group : {_id : "$range", total : { $sum : 1 }}}, {$sort : {total : -1}} ], {allowDiskUse: true} );
References
- Perform Large Sort Operation with External Sort
- Aggregation Pipeline Limits
- MongoDB – Aggregate and Group example
From:一号门
COMMENTS