0

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! ;)

Dominik
  • 6,078
  • 8
  • 37
  • 61
  • What's the problem? When you step through the code in a debugger, which specific line doesn't do what you expect it to do? – Frank van Puffelen Dec 04 '20 at 00:28
  • Sorry the problem is that it does not push the data which i fetch in a foreach loop what i didnt mention in my code sorry for that. @Frank van Puffelen –  Dec 04 '20 at 00:50
  • 1
    That's rather broad. Keep in mind: we can't see what you see, and at this point the code won't even run for any of us, because it has external dependencies. Unless you tell us exactly which specific part of the code doesn't work, it's hard to say much. Hence my question: when you step through the code in a debugger, which specific line doesn't do what you expect it to do? – Frank van Puffelen Dec 04 '20 at 00:54
  • It is not a specific line in the code it's more like is there a function to replace data without removing it first and then pushing it? because what it is doing right now is removing it and then pushing it but it won't push the data so the reservation only gets deleted. @FrankvanPuffelen –  Dec 04 '20 at 12:50
  • There is no operation to move data to a new node/rename an existing node. See https://stackoverflow.com/questions/39107274/is-it-possible-to-rename-a-key-in-the-firebase-realtime-database/39107926#39107926 – Frank van Puffelen Dec 04 '20 at 15:52
  • Sorry for the late respond Frank but thank you for the solution that was exactly what i needed! @FrankvanPuffelen –  Dec 05 '20 at 17:40

0 Answers0