Gary Sieling

RethinkDB: Column Alias Example

If you want to rename columns in a RethinkDB query, you can do it with map:

r.db('test')
 .table('users')
  .map({ login_name: r.row('user_name' ) })

This will rename “user_name” to “login_name”. Note that the output of this is only the columns listed specifically in map – all others would be removed.

If you do this after a “group”, but you’ll need to do an ungroup to get the result correct:

r.db('test')
 .table('users')
 .group('first_name')
 .count()
 .ungroup()
 .map(
   { 
    first_name: r.row('group'),
    val: r.row('reduction') 
  })
Exit mobile version