Mongo Sort Operation Max 33554432 Bytes
发布时间 2020年8月4日 (更新时间 2023年12月12日) • 1 分钟 读完 • 59 字Mongo Sort Operation Max 33554432 Bytes
这几日做 Mongodb 数据库服务迁移,迁移后多处 API 报如下错误:OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit
Mongodb的sort操作是把数据拿到内存中再进行排序的,为了节约内存,默认给 sort 操作限制了最大内存为32Mb,当排序数据量超出了这个大小,问题就出现了。
给排序字段添加索引(index),自己业务使用的 updated_at 字段排序,给此字段添加索引后问题得以解决。
经排查自己的增量迁移 JP Mongodb 作为 C 端主库使用,而为使用原 C 端主库,原 C 端主库的索引是存在的,补充上索引后得以解决。
加大缓冲区,建议还是优先考虑方案一:
//查询值
db.runCommand({ "getParameter" : 1, "internalQueryExecMaxBlockingSortBytes" : 1 } )
//设置新值
db.adminCommand({"setParameter":1, "internalQueryExecMaxBlockingSortBytes":335544320})