Module: Sunspot::MongoMapper::ClassMethods
- Defined in:
- lib/sunspot/mongo_mapper.rb
Instance Method Summary collapse
Instance Method Details
#find_in_batches(options = {}) {|records| ... } ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sunspot/mongo_mapper.rb', line 32 def find_in_batches( = {}, &block) puts "finding in batches: #{.inspect}" batch_size = .delete(:batch_size) || 1000 start = .delete(:start) || 0 .delete(:include) records = [] query().skip(start).order(:id.asc).each do |record| records << record if records.size == batch_size yield records records = [] end end yield records unless records.blank? end |