pymongo.errors:Sort operation used more than the maximum 33554432 bytes of RAM. Add an index,
阿新 • • 發佈:2022-05-04
在 mongo 使用過程中遇到了一個問題,需求就是要對mongo 庫中查詢到資料進行分頁,mongo庫我們知道都會儲存大容量的資料,剛開始使用的 skip 和 limit 聯合使用的方法,來達到擷取所需資料的功能,這種方法在庫裡資料容量小的情況下完全可以勝任,但是如果庫裡資料多的話,上面兩個方法就不好使了,就像題目中那個錯誤,這時會報一個 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.'
db.three_province_poi_v9.find({ "sum_n.sum_4_x":{ $gt:0} } ).sort({"sum_n.sum_4_x":-1})
報錯如下:
Error: error: { "ok" : 0, "errmsg" : "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.", "code" : 96, "codeName" : "OperationFailed" }
按照前面所述:執行
db.three_province_poi_v9.createIndex({"sum_n.sum_4_x": -1})
則在執行語句,即可得到結果
python 下pymongo執行
db_first.three_province_poi_v9.find({"sum_n.sum_4_x":{ "$gt":0} } ).sort([("sum_n.sum_4_x",-1)])
報錯
在上面基礎之上以修改完成。