1.问题描述: 如下问题是因为mongo分组或者排序,因为数据量太大,超出了默认的内存限制。
1).com.mongodb.MongoCommandException: Command failed with error 16945: 'Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.' on server 192.168.4.28:19130. 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, "codeName" : "Location16945" } 2).com.mongodb.MongoQueryException:Query failed with error code 96 and error message Executor error during find command ,cause by errmsg:Sort operation used more than the maxiunum 33554432 bytes of RAM,and an index,or specify a smaller limit 解决方法: 1):直接增大内存:db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320}) 2):为排序分组字段添加索引:db.getCollection("base_person").createIndex({"orgCode":1}).db.xxx.getIndexes()查看所有索引 3):开启使用磁盘: db.getCollection('369_corpus').aggregate([ {$group:{_id:"$title",count:{$sum:1},title:{$addToSet:"$title"},ids:{$addToSet:"$_id"}}},{$match:{count:{$gt:1}}}], {allowDiskUse:true})