// table matérias
"materias" : [
{ id: "m-1", nome: "Português" },
{ id: "m-2", nome: "Matemática" },
{ id: "m-3", nome: "História" },
...
]
// table alunos
"alunos" : [
{id: "a-1", nome: "João", materias: ["m-1", "m-2"] },
{id: "a-2", nome: "Mari", materias: ["m-1"] },
{id: "a-3", nome: "José", materias: ["m-1", "m-2", "m-3"] },
...
]
As I found in the RethinkDB documentation , I know I can make a join for all students in a query when it is a column for an id. How should I do so that I can return an array with all students and their related subjects? I need a return like the example below:
"alunos": [
{
id: "a-1",
nome: "João",
materias: [
{ id: "m-1", nome: "Português" },
{ id: "m-2", nome: "Matemática" }
]
},
{
id: "a-2",
nome: "Mari",
materias: [
{ id: "m-1", nome: "Português" }
]
},
{
id: "a-1",
nome: "João",
materias: [
{ id: "m-1", nome: "Português" },
{ id: "m-2", nome: "Matemática" },
{ id: "m-3", nome: "História" }
]
}
]
I even found an example on the internet how to do this when the reference is between a unique key to a "foreign key" here .
The solution I'm looking for is already done using MongoDB + Mongoose but I'm trying to test the speed + the "real-time" capability it provides.