Solve the problem that MongoDB sorting exceeds the memory limit
Perform a large sort operation (such as aggregation) on the collection with the following error: (test version: MongoDB 3.0.6)
> db.bigdata.aggregate ({$group: {_ id: "$range", total: {$sum: 1}}, {$sort: {total:-1}}); #. Aggregate failed at Error () 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}
Solution method
Reference document: Memory Restrictions
In MongoDB, the maximum internal sort large memory limit is 100m, and if you perform a larger sort, you need to use the allowDiskUse option to write the data to a temporary file to sort.
Add the allowDiskUse option to the query statement:
Db.bigdata.aggregate ([{$group: {_ id: "$range", total: {$sum: 1}, {$sort: {total:-1}}], {allowDiskUse: true})
Summary
The above is introduced by the editor to solve the problem of MongoDB sorting exceeding the memory limit. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!