问题:
综合查询处理异常:
Query failed with error code 96 and error message 'Executor error during find command :: caused by :: errmsg: "Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit."' on server 10.1.1.155:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 96 and error message 'Executor error during find command :: caused by :: errmsg: "Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit."' on server 10.1.1.155:27017
今天遇到一个问题,使用MongoDB进行分页查询的时候,由于数据量比较大,每页显示10条数据,到5000页左右的时候会报上面的错误,很明显,使用skip+limit在小数据量的时候没有问题,当数据量比较大时,MongoDB由于内部机制限制Sort的最大内存为32M,当排序的数据量超过32M就会报如上错误,解决上面问题有两种方法,一种就是增加排序的内存,另一种就是对排序的字段创建索引。 一、重新分配更大的排序内存(320M):
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})
二、为排序的字段创建索引
db.getCollection("base_person").createIndex({"orgCode":1})