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.