1. 程式人生 > >OperationFailed Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit

OperationFailed Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit

imu command mongo sed 大內存 gson style fan index

  按照錯誤提示,知道這是排序的時候報的錯,因為 mongo 的 sort 操作是在內存中操作的,必然會占據內存,同時mongo 內的一個機制限制排序時最大內存為 32M,當排序的數據量超過 32M,就會報上面的這個錯,解決辦法就像上面提示的意思,一是加大 mongo 的排序內存,這個一般是運維來管,也有弊端,就是數據量如果再大,還要往上加。另一個辦法就是加索引,這個方法還是挺方便的。創建索引及時生效,不需要重啟服務。

  下面記錄下 加大 mongo 的排序內存的方法,親測有效:

進入mongodb所在目錄下的bin目錄,運行mongo,運行db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320}),即可將32MB的內存更改為320MB;

不推薦此種方法;

  加索引的方法,博主並沒有親測,僅作參考:

  對需要排序的字段建索引 db.stotal.ensureIndex({‘type‘: -1}),索引字段根據自己的時間情況定。

OperationFailed Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit