Firebase将数据追加到节点
问题描述:
如何将数据追加到Firebase中的节点?值更新只是一个字符串,而不是字典。Firebase将数据追加到节点
Firebase应该能够增加每个项目。我认为update
会工作,但只会更新字典。当我尝试设置值时,它会擦除所有内容。
FIRDatabase().reference().database.childRef(refUrl: path).updateChildValues([:])
实施例:
node{
1:itemOne
2:itemTwo
3:itemThree
}
答
从火力文档
https://firebase.google.com/docs/database/ios/read-and-write
Update specific fields To simultaneously write to specific children of a node without overwriting other child nodes, use the updateChildValues method.
试somethi ng like
let key = ref.child("node").childByAutoId().key
let post = ["uid": userID,
"author": username,
"title": title,
"body": body]
let childUpdates = ["/posts/\(key)": post,
"/user-posts/\(userID)/\(key)/": post]
ref.updateChildValues(childUpdates)