最近在使用mongodb的时候由于数据量比较大,在查询的时候出现了如下错误。
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
查询的语句添加了排序,mongo排序全部在内存中操作,而mongo的默认内存32m,所以内存不足包的错误,解决办法在此记录下:
1:设置扩大内存
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320}) //不推荐使用
2:添加索引
db.getCollection('MID_AIRLINE_DATA').createIndex({time_point:1}) 1:升序 -1:降序