With this function i want to insert data into my firebase database:
function insertDaten(titel) {
var ref = firebase.database().ref();
ref.on("value", function (snapshot) {
var json_elemente = snapshot.val().notes;
var keys = Object.keys(json_elemente);
var count = Math.max.apply(null, keys) + 1;
firebase.database().ref("notes/" + count).set({
id: parseInt(count) + 1,
text: "",
titel: titel,
bild: ""
});
});
}
but everytime i run it, it seems to loop and create as many datasets as it can before the program shuts down. i've tried to just add a return; but that doesn't seem to work either.