'How to pass own unique key in firebase and update it as well without destroying the structure?

I am currently trying to make a script where I pass my own unique key in firebase as primary key. It needs to work like this

StudentData
  -Student Unique id
    - referadID : "active",
    - referadID2 : "inactive",
    - referadID3 : "active",
  -Student Unique id2
    -referadIDnew : "active",

Here every student refers another student and once a refered student join that refered student who joined has his own unique id which stores value of active or inactive. The problem here is that if I use push it will generate a unique id which I don't want because it will make it difficult to work while using sorting. I don't want to do it. How can I create my own unique key in studentUniqueid2. I tried using transaction instead of push but the issue is that transaction instead of adding another key value pair would simply update the whole key leaving only the latest student unique id in the table which I don't want. Here is my code

let createData=adminDatabase.ref('/ReferralSystem/joinedtransactionlog');
createData.transaction(function(currentData){

  if(currentData !== InviterId){
    return {
      [InviterId]: {
        [member.id] : "active" 
      }
    }
  }else{
    console.log("curretn data exists");
  }
});

I am using javascript and working on firebase realtime database system with platform of Admin.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source