正如标题所说,我不能得到之间的区别update和set.此外,文档无法帮助我,因为如果我使用set,更新示例的工作原理完全相同.
update来自文档的示例:
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);
}
Run Code Online (Sandbox Code Playgroud)
使用相同的例子 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; …Run Code Online (Sandbox Code Playgroud)