each
ReQL command: each
Command syntax
cursor.each { ... } array.each { ... } feed.each { ... }
Description
Lazily iterate over a result set one element at a time.
RethinkDB sequences can be iterated through via the Ruby Enumerable interface; use standard Ruby commands like each
blocks to access each item in the sequence.
Example: Let’s process all the elements!
cursor = r.table('users').run(conn) cursor.each { |doc| process_row(doc) }
Example: Stop the iteration prematurely and close the connection manually.
cursor = r.table('users').run(conn) cursor.each do |doc| ok = process_row(doc) if not ok cursor.close() break end end
Related commands
Get more help
Couldn't find what you were looking for?
- Ask a question on Stack Overflow
- Chat with us and our community on Slack
- Talk to the team on IRC on #rethinkdb@freenode.net — via Webchat
- Ping @rethinkdb on Twitter
- Post an issue on the documentation issue tracker on GitHub
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/ruby/each/