Samuel Goldenbaum
Samuel Goldenbaum

Reputation: 18909

How do you perform projections in RethinkDB?

Given the following data in two tables:

Employees
[
   {"name": "person 1", "dept": 1},
   {"name": "person 2", "dept": 1},
   {"name": "person 3", "dept": 2}
]

Departments
[
   {"name": "design", "id": 1},
   {"name": "development", "id": 2}
]

To run a query with a join:

r.db('mydb').table('employees').eqJoin('dept', r.db('mydb').table('departments')).zip();

This will merge the results and I end up with a single 'name' property from the departments overwriting the name from the employees table.

How to you handle projections in RethinkDB to handle this to that I can end up with the name from both the Employee and Department tables?

Upvotes: 1

Views: 132

Answers (1)

neumino
neumino

Reputation: 4353

You can manually map

r.db('mydb').table('employees')
  .eqJoin('dept', r.db('mydb').table('departments'))
  .map(function(doc) {
    return {
      personName: left("name"),
      departmentName: right("name"),
      // etc.
    }
  })

Upvotes: 1

Related Questions