Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Conversation

@fancyremarker
Copy link

Caveat: This is potentially very risky, so feel free to reject. I'm not familiar enough with Mongoid to understand all the implications of this change. That said, we've been using it in production for some time without any apparent ill effects.

The Mongo Ruby driver (and thus Mongoid 2.x) supported iterating over a cursor outside a block, using such operations as take(). For example:

batch_size = 10
cursor = session[:users].find.cursor
while (users = cursor.take(batch_size)).present?
  # Do stuff...
end
# Do more stuff...

This was a convenient pattern for implementing lots of algorithms in a more readable way than if they were written using each(). This patch reintroduces this convenience.

cc: @dblock

The Mongo Ruby driver (and thus Mongoid 2.x) supported iterating over a
cursor outside a block, using such operations as take(). For example:

    batch_size = 10
    cursor = session[:users].find({}).cursor
    while (users = cursor.take(batch_size)).present?
      # Do stuff...
    end
    # Do more stuff...

This was a convenient pattern for implementing lots of algorithms in a
more readable way than if they were written using each().
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 2d854a0 on fancyremarker:cursor-cache-updated into 073e30b on mongoid:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) when pulling 2d854a0 on fancyremarker:cursor-cache-updated into 073e30b on mongoid:master.

@dblock
Copy link
Contributor

dblock commented Dec 2, 2013

@fancyremarker looks like Travis build failed, not sure if this is introduced by this change

@fancyremarker
Copy link
Author

@dblock: I couldn't see how it was connected, but that's because of my own ignorance. FWIW, specs did pass locally for me.

@arthurnn arthurnn modified the milestones: 2.0.0, 2.0.3 Nov 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants