设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

MongoDB排序超过内存限制的解决方法

2015-10-25 19:11| 发布者: joejoe0332| 查看: 5153| 评论: 0|原作者: codecloud.net|来自: codecloud.net

摘要: 对集合执行一个大排序操作(如聚合),出现以下错误:(测试版本:MongoDB 3.0.6)

对集合执行一个大排序操作(如聚合),出现以下错误:(测试版本:MongoDB 3.0.6)

> 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
       
}

解决方法

参考文档:Memory Restrictions

MongoDB中,内排序大内存限制最大为100M,如果执行一个更大的排序,需要使用 allowDiskUse 选项来将数据写到临时文件来排序。

在查询语句中添加 allowDiskUse 选项:

db.bigdata.aggregate(
[
       
{$group : {_id : "$range", total : { $sum : 1 }}},
       
{$sort : {total : -1}}
],
       
{allowDiskUse: true}
);

酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部