简体   繁体   中英

Nodejs get two joined tables in rethinkdb

I'd like to join two tables and write get url with joined table (make get, post, delete on joined table). I know how to do it with single table (eg):

 app.get('/employees', (req, res) => {
   r.table('employees').run(connection).then((cursor) => {
   // console.log(cursor)
   cursor.toArray().then((employees) => res.json(employees))
   })
 })

So i found in Rethinkdb documentation useful command: https://www.rethinkdb.com/docs/table-joins/

r.table("employees").eq_join("company_id", r.table("companies")).zip().run()

Returns the following result:

{
"id": "064058b6-cea9-4117-b92d-c911027a725a",
"name": "Jean-Luc Picard",
"company_id": "064058b6-cea9-4117-b92d-c911027a725a",
"rank": "captain",
"company": "Starfleet",
"type": "paramilitary"

}

How should I write my get code in nodejs? I don't know how can I name the merged table or how to call it.

Following the documentation:

If you use the zip command after join, 
the document from the right table will be merged into the left one.

I'd assume the table will still be named "employees"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM