报错
今天在查询 mongo 过程中一直报错:
:Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit., full error: {'ok': 0.0, 'errmsg': 'Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.', 'code': 96, 'codeName': 'OperationFailed'}
原因
原因:Sort operation used more than the maximum 33554432 bytes of RAM.
,
mongodb的sort操作是把数据拿到内存中再进行排序的,为了节约内存,默认给sort操作限制了最大内存为32Mb,当数据量越来越大直到超过32Mb的时候就自然抛出异常了!
解决方式
1、 报错原因是内存不够,那么进行修改配置默认内存空间
2、 根据内容提示,为排序字段创建索引
# 为时间排序字段创建索引
db.collection.createIndex({"input_time":-1})
# 修改默认配置的内存空间为320M
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})