ReQL command: getAll
Command syntax
table.getAll([key, key2...]) → selection
Description
Get all documents where the given value matches the value of the requested index.
Example: Secondary index keys are not guaranteed to be unique so we cannot query via get when using a secondary index.
r.table("marvel").getAll("man_of_steel").optArg("index", "code_name").run(conn);
Example: Without an index argument, we default to the primary index. While get
will either return the document or null
when no document with such a primary key value exists, this will return either a one or zero length stream.
r.table("dc").getAll("superman").run(conn);
Example: You can get multiple documents in a single call to get_all
.
r.table("dc").getAll("superman", "ant man").run(conn);
Note:
getAll
does not perform any de-duplication. If you pass the same key more than once, the same document will be returned multiple times.
Example: You can use args with getAll
to retrieve multiple documents whose keys are in a list. This uses getAll
to get a list of female superheroes, coerces that to an array, and then gets a list of villains who have those superheroes as enemies.
r.do(
r.table("heroes").getAll("f").optArg("index", "gender")
.g("id").coerceTo("array"),
heroines -> r.table("villains").getAll(r.args(heroines))
).run(conn);
Calling getAll
with zero arguments—which could happen in this example if the heroines
list had no elements—will return nothing, i.e., a zero length stream.
Secondary indexes can be used in extremely powerful ways with getAll
and other commands; read the full article on secondary indexes for examples using boolean operations, contains
and more.
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/java/get_all/