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 }