MongoDB排序内存不够问题

问题:mongodb

综合查询处理异常:
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就会报如上错误,解决上面问题有两种方法,一种就是增长排序的内存,另外一种就是对排序的字段建立索引。 1、从新分配更大的排序内存(320M):code

db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})

2、为排序的字段建立索引server

db.getCollection("base_person").createIndex({"orgCode":1})
相关文章
相关标签/搜索