I have a reservation system where I want players to change there data like on which court they play or which date or which time. I tried to replace the data but there is no replace function so I did this:
self = this
const reserveringsref = firebase.database().ref('Reserveringen/')
reserveringsref.once('value', function(snapshot){
const email = self.email
const lidnummer = self.lidnummer
const baan = self.baan
const medespeler1 = self.medespeler1
const medespeler2 = self.medespeler2
const medespeler3 = self.medespeler3
const datum = self.datum
const tijd = self.tijd
const abcd = reserveringsref.orderByChild('Lidnummer').equalTo(self.lidnummer);
//this only runs when the reserveration is already in the system so that it removes the old reservation and pushes the new reservation but the problem is it never pushes the reservation
//also some if checks with the constants mentioned above
abcd.on('value', function(abcdSnap){
var a = abcdSnap.val();
var b = Object.keys(a)[0];
reserveringsref.child(b).remove();
})
reserveringsref.push({
Lidnummer: lidnummer,
Baan: baan,
Medespeler1: medespeler1,
Medespeler2: medespeler2,
Medespeler3: medespeler3,
Datum: datum,
Tijd: tijd,
Email: email
})
Can anyone tell me what am I doing wrong? And some explanation with it so that I can learn from my mistake. Thanks in advance! ;)