W3cubDocs

/RethinkDB JavaScript

ReQL command: getAll

Command syntax

table.getAll([key, key2...], [, {index:'id'}]) → 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', {index:'code_name'}).run(conn, callback)

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, callback)

Example: You can get multiple documents in a single call to get_all.

r.table('dc').getAll('superman', 'ant man').run(conn, callback)

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', {index: 'gender'})('id').coerceTo('array'),
    function(heroines) {
        return r.table('villains').getAll(r.args(heroines));
    }
).run(conn, callback)

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.

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/javascript/get_all/