How to rename a field in rethink while doing a join
rethinkdb
Solution
You need to use parentheses instead of square bracket to select a field.
r.db('testdb')
.table('eco')
.eqJoin('project_id', r.db('testdb').table('projects'))
.map(
function(doc){
return doc.merge(function(){
return {'right': {'p_name': doc('right')('name')}}
})
})
.without({'right': {'id': True}})
.without({'right': {'name': True}})
.zip()
Site notes:
- You shouldn't use `r.row` if you use a function -- it's one or the other, not both.
- You don't need to wrap everything in r.expr
Problem
I'm trying to do a join on 2 tables in rethinkdb with the following query: ``` r.db('testdb') .table('eco') .eqJoin('project_id', r.db('testdb').table('projects')) .map( function(){ r.row.merge(function(){ r.expr({'right': r.expr({'p_name': r.row['right']['name']})}) }) }) .without(r.expr({'right': r.expr({'id': True})})) .without(r.expr({'right': r.expr({'name': True})})) .zip() I keep getting the following error: ``` TypeError: Cannot read property 'name' of undefined There is a name field on the eco table as well as the projects table.