1
具有大约800-900条记录的Mongo备份模型我试图迭代并使用某些属性生成CSV。迭代“大”集合时Rails 4和Mongo DB 4.x错误
所以它看起来像这样:
each do |car|
csv << columns.map { |column| car.__send__(column) }
end
而且我得到的错误是这样的:
A Moped::Errors::QueryFailure occurred in cars#index:
The operation: #<Moped::Protocol::Query
@length=94
@request_id=376
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="app555555.cars"
@skip=0
@limit=0
@selector={"$query"=>{}, "$orderby"=>{"created_at"=>-1}}
@fields=nil>
failed with error 10128: "too much data for sort() with no index. add an index or specify a smaller limit"
See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
app/models/car.rb:84:in `block in to_csv'
感谢grimsock,我在默认顺序列(它是'created_at')上添加了索引,它的工作原理! –