I have went through Firebase doc, plus I have found a few topics on stackoverflow about set() vs. update() in Firebase: e.g.here
It is very clear what is the difference between the two of them.
In the following code, why does update() overwrites my existing data?
function saveChanges(event) {
event.preventDefault();
let modifiedTitle = document.getElementById('blog-title').value;
let modifiedContent = document.getElementById('blog-content').value;
let modifiedId = document.getElementById('blog-id-storage').innerHTML;
let postData =
title: modifiedTitle,
content: modifiedContent
};
let updates = {};
updates[modifiedId] = postData;
firebase.database().ref().child('posts/').update(updates);
}
I originally have a title, content, datePosted and Id and when I update it the title and content gets updated and dataPosted and Id gets deleted. Why? While this should be the behavior of set()?