Sha256: 2961daa1ed3a87b68cedb3748c48e4264e8451c6aa909bc17ac4c5b5f63799f6

Contents?: true

Size: 358 Bytes

Versions: 27

Compression:

Stored size: 358 Bytes

Contents

module MongoModel
  class Scope
    module Batches
      def in_batches(batch_size=1000)
        offset = 0
        
        begin
          documents = offset(offset).limit(batch_size).all
          yield documents if block_given? && !documents.empty?
          offset += batch_size
        end until documents.size < batch_size
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/support/scope/batches.rb
mongomodel-0.5.4 lib/mongomodel/support/scope/batches.rb
mongomodel-0.5.3 lib/mongomodel/support/scope/batches.rb
mongomodel-0.5.2 lib/mongomodel/support/scope/batches.rb
mongomodel-0.5.1 lib/mongomodel/support/scope/batches.rb
mongomodel-0.5.0 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.9 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.8 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.7 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.6 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.5 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.4 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.3 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.2 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.1 lib/mongomodel/support/scope/batches.rb
mongomodel-0.4.0 lib/mongomodel/support/scope/batches.rb
mongomodel-0.3.6 lib/mongomodel/support/scope/batches.rb
mongomodel-0.3.5 lib/mongomodel/support/scope/batches.rb
mongomodel-0.3.4 lib/mongomodel/support/scope/batches.rb
mongomodel-0.3.3 lib/mongomodel/support/scope/batches.rb