Skip to content

Instantly share code, notes, and snippets.

@anvyzhang
Last active December 18, 2015 06:09
Show Gist options
  • Save anvyzhang/5737527 to your computer and use it in GitHub Desktop.
Save anvyzhang/5737527 to your computer and use it in GitHub Desktop.
When a mongo collection is too large for RAM, use cursor this way.
App.db.collection('apps').find({'name' => 'test_name'},{:timeout => false}){|ptr| ptr.each{|x| puts x['user_id']}}
# NOTE in cursor iteration
ptr.each{|x|
x.user_id # WRONG
x['user_id'] # RIGHT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment