Mongo的排序内存 默认32M,超过后,查询报错【Sort operation used more than the maximum 33554432 bytes of RAM】

报错问题

Query failed with error code 96 and error message 'Executor error during find command :: caused by :: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.

思路

  • 提示说添加索引,或者增加内存参数
  • 按照提示,增加过索引,因为我排序字段有两个,刚开始建立的独立索引时,无效。
  • 建立的是联合索引,确实可以解决内存问题了,但是查询时mongo选择了这个索引,没有选择更优的索引字段,导致查询变慢了
  • 遂将索引删除后,走了添加排序内存的方式 将原先的32M改为了100M 查询后,不报错且正常
    db.adminCommand({ setParameter: 1, internalQueryExecMaxBlockingSortBytes: 104857600 });
posted @ 2025-05-22 15:21  darling331  阅读(53)  评论(0)    收藏  举报