How to structure the database in Firebase

1

I am somewhat of a layman in NoSql, and I have a question about performace in my Firebase database, it is currently organized as follows

As you can see the reference for the student and the product that are in the Sale are their respective IDs, so for me to display the name of these items I need to do two new searches in the bank, one in the Students node and another in the Products , my code now looks like this:

        vendasRef.orderByKey().on('value', snap => {
        const vendas = [];
            snap.forEach(shot => {
              rootRef.child('alunos/${shot.val().aluno}').orderByKey().on('value',function(nAluno){
                rootRef.child('produtos/${shot.val().produtos}').orderByKey().on('value',function(nProduto){
                  vendas.push({...shot.val(), key: shot.key , nomAluno:nAluno.val().nome, nomProduto:nProduto.val().nome});
                })
              })
          });
          this.setState({vendas:vendas});
         });

Would that be the best way? or would it be better to save the Student and Product name together on this node? If so, would not that be too redundant?

    
asked by anonymous 20.11.2018 / 05:51

0 answers