Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.15 KB

to_array.md

File metadata and controls

46 lines (33 loc) · 1.15 KB
layout api-command
language Python
permalink api/python/to_array/
command list
related_commands
next for (cursor) close (cursor)
next/
each/
close-cursor/

Command syntax

{% apibody %} list(cursor) {% endapibody %}

Description

Retrieve all results as a list.

RethinkDB sequences can be iterated through via the Python Iterable interface; to coerce a cursor into a list, use the Python list() class constructor.

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

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

The equivalent query with a for loop would be:

cursor = r.table('users').run()
for doc in cursor:
    process_results(doc)

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