As the title says, I can't get the differences between update
and set
. Also the docs can't help me, as the update example works exactly the same if I use set instead.
The update
example from the docs:
function writeNewPost(uid, username, title, body) {
var postData = {
author: username,
uid: uid,
body: body,
title: title,
starCount: 0
};
var newPostKey = firebase.database().ref().child('posts').push().key;
var updates = {};
updates['/posts/' + newPostKey] = postData;
updates['/user-posts/' + uid + '/' + newPostKey] = postData;
return firebase.database().ref().update(updates);
}
The same example using set
function writeNewPost(uid, username, title, body) {
var postData = {
author: username,
uid: uid,
body: body,
title: title,
starCount: 0
};
var newPostKey = firebase.database().ref().child('posts').push().key;
firebase.database().ref().child('/posts/' + newPostKey).set(postData);
firebase.database().ref().child('/user-posts/' + uid + '/' + newPostKey).set(postData);
}
So maybe the example from the docs should be updated, because now it looks like update
and set
do the exact same thing.
Kind regards, Bene