在使用Java查询MongoDB的时候报错:
com.mongodb.MongoQueryException: 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.'
解决办法:
1、给排序字段增加索引
2、增加排序操作内存,默认为32M
db.adminCommand({setParameter: 1,internalQueryExecMaxBlockingSortBytes: xxxx}),xxxx的取值为自己想要的内存上限,比如,256M=256*1024*1024=268435456。此命令即时生效。(注意:当MongoDB重启时,如果配置文件中未设置,则会恢复默认的值32M。)
所以最好在配置文件中添加配置:
setParameter:
internalQueryExecMaxBlockingSortBytes: 268435456