MongoDB排序超过内存限制

MongoDB查询数据默认最大内存为100M,如果超过,则需要使用allowDiskUse选项,可以将查询结果保存到临时文件进行排序分组。

db.license.aggregate(
  {"$match" : {"issue_unit" : "001002030", "state" : 11}},
  {"$group" : {"_id" : "$license_name", "count" : {"$sum" : 1}}},
  {allowDiskUse : true}
)

 

否则,会抛出类似异常:

The full response is { "ok" : 0.0, "errmsg" : "Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.", "code" : 16945 }

posted @ 2021-04-07 14:56  一隅桥畔  阅读(614)  评论(0)    收藏  举报