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

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

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

一、为该字段添加索引

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

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

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

相关文章:

  • 2021-09-16
  • 2021-08-29
  • 2022-12-23
  • 2021-05-21
  • 2021-08-06
  • 2021-10-24
  • 2022-12-23
  • 2021-06-04
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2021-12-30
  • 2021-10-19
相关资源
相似解决方案