ReQL command: to_a

Command syntax

cursor.to_a()

Description

Retrieve all results as an array.

RethinkDB sequences can be iterated through via the Ruby Enumerable interface; to coerce a cursor into an array, use the Ruby to_a() command.

Example: For small result sets it may be more convenient to process them at once as an array.

cursor = r.table('users').run()
users = cursor.to_a()
process_results(users)

The equivalent query with an each block would be:

cursor = r.table('users').run()
cursor.each { |doc|
    process_results(doc)
}

Note: Because a feed is a cursor that never terminates, using to_a with a feed will never return. Use each instead. See the changes command for more information on feeds.

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/ruby/to_array/