2014-12-28 21 views
0

這樣做查詢,當我達到某種內存的限制,這裏的錯誤:我蒙戈查詢太大,我達到了內存問題

The operation: #<Moped::Protocol::Query 

    @length=100 

    @request_id=962 

    @response_to=0 

    @op_code=2004 

    @flags=[] 

    @full_collection_name="test_db.cases" 

    @skip=1650 

    @limit=150 

    @selector={"$query"=>{}, "$orderby"=>{"created_at"=>1}} 

    @fields=nil> 

failed with error 17144: "Runner error: Overflow sort stage buffered data usage of 33555783 bytes exceeds internal limit of 33554432 bytes" 


See https://github.com/mongodb/mongo/blob/master/docs/errors.md 

for details about this error. 

有兩個解決方案,我能想到的:

1)增加緩衝區限制。這需要mongo 2.8這是一些不穩定的版本,我不得不手動安裝。

2)分解查詢?大塊呢?這是查詢看起來是這樣的:

upload_set = Case.all.order_by(:created_at.asc).skip(@set_skipper).limit(150).each_slice(5).to_a

@set_skipper生長每調用一次該方法就會減少150。

任何幫助?

回答

3

http://docs.mongodb.org/manual/reference/limits/

Sorted Documents

MongoDB will only return sorted results on fields without an index if the combined size of all documents in the sort operation, plus a small overhead, is less than 32 megabytes.

你嘗試在created_at使用索引?這應該消除這個限制。