W3cubDocs

/RethinkDB Java

ReQL command: next

Command syntax

cursor.next([wait])

Description

Get the next element in the cursor.

The optional argument specifies whether to wait for the next available element and how long to wait:

  • true: Wait indefinitely (the default).
  • false: Do not wait at all. If data is immediately available, it will be returned; if it is not available, a ReqlTimeoutError will be raised.
  • number: Wait up to the specified number of seconds for data to be available before raising ReqlTimeoutError.

The behavior of next will be identical with false, null or the number 0.

Calling next the first time on a cursor provides the first element of the cursor. If the data set is exhausted (e.g., you have retrieved all the documents in a table), a NoSuchElementException error will be raised when next is called.

Example: Retrieve the next element.

Cursor cursor = r.table("superheroes").run(conn);
Object doc = cursor.next();

Example: Retrieve the next element on a changefeed, waiting up to five seconds.

Cursor cursor = r.table("superheroes").changes().run(conn);
Object doc = cursor.next(5);

Note: RethinkDB cursors can be iterated through via the Java Iterable and Iterator interfaces. The canonical way to retrieve all the results is to use a for loop or toList.

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/next/