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就会报如上错误,解决上面问题有两种方法,一种就是增加排序的内存,另一种就是对排序的字段创建索引。 一、重新分配更大的排序内存(320M):

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

二、为排序的字段创建索引

db.getCollection("base_person").createIndex({"orgCode":1})

转载于:https://my.oschina.net/u/2477500/blog/2049388

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值