Rails 4 和 Mongo DB 4.x 遍历 "big" 集合时出错
Rails 4 and Mongo DB 4.x error when iterating over the "big" collection
Mongo 支持的模型包含大约 800-900 条记录,我正在尝试迭代并使用某些属性生成 CSV。
所以看起来像这样:
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'
您可能缺少索引。这是关于在 mongo DB When to index, what to index in Mongoid? and http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#id12
中添加索引的更多信息
Mongo 支持的模型包含大约 800-900 条记录,我正在尝试迭代并使用某些属性生成 CSV。
所以看起来像这样:
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'
您可能缺少索引。这是关于在 mongo DB When to index, what to index in Mongoid? and http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#id12
中添加索引的更多信息