Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using the `getAll` command to query multiple keys in RethinkDB 1.7.

Querying by multiple keys

The previous releases of RethinkDB allowed querying indexes as follows:

// Three ways to get the user with primary key 5
r.table('users').get(5)
r.table('users').getAll(5)
r.table('users').getAll(5, {index: 'id'})

// Query a secondary index
r.table('users').getAll('Smith', {index: 'last_name'})

However, if you wanted to get all documents from a set of keys, you had to resort to using map:

// Three ways to get the users with primary keys 5 or 6
r.expr([5, 6]).map(r.table('users').get(r.row))
r.expr([5, 6]).map(r.table('users').getAll(r.row))
r.expr([5, 6]).map(r.table('users').getAll(r.row, {index: 'id'}))

// Query a secondary index
r.expr(['Smith', 'Jones']).map(r.table('users').getAll(r.row, {index: 'last_name'}))

As of RethinkDB 1.7, you can now pass multiple arguments to getAll to avoid the cumbersome map syntax above:

// Two ways to get the users with primary keys 5 or 6
r.table('users').getAll(5, 6)
r.table('users').getAll(5, 6, {index: 'id'})

// Query a secondary index
r.table('users').getAll('Smith', 'Jones', {index: 'last_name'})

See more about the 1.7 release in the release announcement.

@aftabaslam
Copy link

aftabaslam commented Sep 6, 2016

Very Useful link, thanks for sharing.

@verona-rupes
Copy link

verona-rupes commented Dec 17, 2016

Thanks for sharing !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment