Reputation: 23
var a = prompt("What is your phone number");
var database = firebase.database();
var fruits = database.ref('fruits');
var data = {
name: (a),
count: (a)
}
database.ref('fruits').push(data);
fruits.push(data, finished);
function finished(error) {
if (error) {
console.log('ooops');
} else {
console.log('data saved!');
}
}
var ref = firebase.database().ref();
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (error) {
console.log("Error: " + error.code);
});
var playersRef = firebase.database().ref("fruits");
playersRef.orderByChild("name").on("child_added", function(data) {
var PD = (data.val().name);
confirm(PD)
});
For some reason, this code is producing a duplicate of itself in the firebase real-time database. Can anyone help me with this?
Upvotes: 1
Views: 681
Reputation: 61
It looks like you have two consecutive lines of code that each push the same data, resulting in your duplicate.
database.ref('fruits').push(data);
fruits.push(data, finished);
Try deleting one of those lines
Upvotes: 1