I am writing comments to movies. But with this code i just can add one comment. When i add second comment, the first comment changes with the second one. But i want to add more comments for my movie. How can i achieve that? (show variable is my movie's id. My movie's id is one.) The code is:
btnComment.addEventListener('click',(e)=>{
var movieComment = document.getElementById('textComment').value;
set(child(firebaseRef, 'Movies/'+ show + '/Comments/'), {
movieComment: movieComment
});
});
If you want to keep a list of nodes in Firebase, consider using the push() method. To add a comment to the list with that:
push(child(firebaseRef, 'Movies/'+ show + '/Comments'), movieComment})
So we call push instead of set here, which generates a new child node with a unique ID under Comments.
Also see the Firebase documentation on adding a child node to a list and this classic blog post: Best Practices: Arrays in Firebase.