1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Great! Glad to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.