Gary Sieling

RethinkDB: RIGHT JOIN Example

RethinkDB has a function called “outerJoin”, which actually does a left join.

For example, this finds users and adds their audit trail history (if any):

r.db('test')
 .table('user_actions')
 .outerJoin(r.table('users'),
    (action, user) => 
      action('user_id').eq(user('id')))
 .zip()

If instead you want to start with audit history and add users (if they exist) you have to swap everything manually, since at this time there is no right join:

r.db('test')
 .table('users')
 .outerJoin(r.table('user_actions'),
    (user, action) => 
      action('user_id').eq(user('id')))
 .zip()
Exit mobile version