W3cubDocs

/RethinkDB Java

ReQL command: for

Command syntax

for (doc : <Cursor>) { ... }

Description

Lazily iterate over a result set one element at a time.

RethinkDB cursors can be iterated through via the Java Iterable and Iterator interfaces; use standard Java commands like for loops to access each item in the sequence.

Example: Let’s process all the elements!

Cursor cursor = r.table("users").run(conn);
for (Object doc : cursor) {
    System.out.println(doc);
}

Example: Stop the iteration prematurely and close the connection manually.

Cursor cursor = r.table("users").run(conn);
for (Object doc: cursor) {
    ok = processRow(doc);
    if (ok == false) {
        cursor.close();
        break;
    }
}

Related commands

Get more help

Couldn't find what you were looking for?

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