mongodb|mongodb分页排序获取数据 导致超出32M限制

【mongodb|mongodb分页排序获取数据 导致超出32M限制】转自
mongodb 分页排序获取数据导致超出32M限制:Sort operation used more than the maximum 33554432 bytes of RAM
异常:

"exception":"org.springframework.data.mongodb.UncategorizedMongoDbException", "message":"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 smaller limit.' on server 127.0.0.1:27017; nested exception is com.mongodb.MongoQueryException: 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 smaller limit.' on server 127.0.0.1:27017"

处理方式:
  • 加索引
db.yourCollection.createIndex({:<1 or -1>})

  • 扩大排序内存的限制,例如扩大到320M
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})

如果你已经加了索引了还是报32M,那么目前只能扩大内存了。

    推荐阅读