Skip to content

Instantly share code, notes, and snippets.

@justinko
Created October 8, 2011 12:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save justinko/1272234 to your computer and use it in GitHub Desktop.
Save justinko/1272234 to your computer and use it in GitHub Desktop.
def find_in_batches(model)
current_batch, count = 0, model.count
while count > 0 do
model.all.skip(current_batch * 1000).limit(1000).each do |doc|
yield doc
end
count -= 1000
current_batch += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment