如何将孩子添加到Firebase播放器UID?

时间:2017-10-31 16:45:06

标签: firebase firebase-realtime-database

我尝试将子节点添加到具有UID的玩家。我用了孩子(“node_1”)。它只创建一个节点。如何向此节点添加项目?

2 个答案:

答案 0 :(得分:0)

要解决此问题,每次尝试向数据库添加数据时都需要unique identifier。由于Firebase数据库是NoSQL数据库,并且构造为键和值对,因此每个节点都是一个Map,这意味着在Map的情况下,它将旧值替换为新值。

幸运的是,Firebase提供了一个名为push()的方法。您可以像这样使用它:

yourRef.push().child(name).setValue("John");

答案 1 :(得分:0)

您使用哪一个添加子节点? Web,Ios还是Android?

Alex Mamo是对的:"每次尝试将数据添加到数据库时都需要有一个唯一的标识符"

使用网络:

let node = firebase.database().ref().child(Your node)
var key= node.push().key //  Get a key for a new
node.child(key).set(new value)

https://firebase.google.com/docs/database/web/read-and-write?authuser=0

用于IOS:

let key = ref.child("posts").childByAutoId().key

https://firebase.google.com/docs/database/ios/read-and-write?authuser=0

对于Android:

String key = mDatabase.child("posts").push().getKey()

https://firebase.google.com/docs/database/android/read-and-write?authuser=0

希望能帮到你。