mongodb報錯一例

 

開發程序報錯信息:mongodb

Caused by: com.mongodb.MongoException: Executor error: 函數

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

從程序報錯中能夠看到是排序的內存不足。spa

 

解決辦法:3.x版本orm

  use admin排序

  db.adminCommand({getParameter:"*"})    #查看參數的配置索引

  db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})  #修改內存爲排序爲320M內存

 

其餘解決方案:(經過建立索引方式)  ci

  db.你的collection.createIndex({"你的字段": -1}),此處 -1 表明倒序,1 表明正序;開發

  db.你的collecton.getIndexes();

 

  

參考官方文檔:

  https://docs.mongodb.com/manual/reference/method/cursor.sort/#cursor.sort

  https://docs.mongodb.com/manual/tutorial/optimize-query-performance-with-indexes-and-projections/

 

對於以上問題推薦解決方案:

  1.優化查詢和索引。  2.減小輸出列(限制輸出列個數)或行(如limit函數,或限制輸入查詢_id數量)。  3.將查詢分2步,第1步只輸出_id,第2步再經過_id查明細。  均可以解決內存中排序溢出問題。

相關文章
相關標籤/搜索