首页 > 技术文章 > Query failed with error code 96 and error message 'Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smal

drunkPullBreeze 2019-06-10 16:59 原文

首先问题很明确,当我对一个没有建索引的字段做find,然后做sort的时候,可能触发sort的size的32MB限制,而mongodb的sort操作是把数据拿到内存中再进行排序的,为了节约内存,默认给sort操作限制了最大内存为32Mb,当数据量越来越大直到超过32Mb的时候就自然抛出异常了!

解决方案有两种(建议添加索引):

一、为该字段添加索引

db.CollectionName(表名).createIndexes({"title":1})  //title为字段名,1为正序,-1为倒序

二、修改默认配置,把sort时可以用的内存设置大点

db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320}) //该命令是扩大sort限制为320MB

推荐阅读