vendredi 23 mars 2018

delete data from firebase using key

This is my first time using firebase. My database looks like:enter image description here

I have the key and would like to remove the node for that key:

var dataKey = $("#trainClicked").attr("data-key");
var ref = database.ref("trains/" + changeTrain);
ref.on('value', function (snapshot) {
console.log(snapshot)
    if (snapshot === null) {
        console.log("does not exist")
    } else {
        return database.ref().remove(dataKey)
   }
});

This removes the entire database and gives an error:

return database.ref().remove(dataKey)

I have read through firebase docs and through many posts here but I still cant get it to work. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire