Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Solve the problem that MongoDB sorting exceeds the memory limit

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report