简体   繁体   中英

Firebase how can I add a child node with a given name?

If I have a /users folder on Firebase realtime db, with inside various UID , how can I add a child called /history under an UID ?

Using .child('users').child(UID).push() it creates a unique id, I'd like it to be called "history" instead, how can I achieve it?

Calling push() generates a new unique location under the reference on which you call it. To instead control the key of the location you write to. use child :

ref.child('users').child(UID).child("history").set("hello")

If you'd instead want to create a new unique child node under the history node, you'd do:

ref.child('users').child(UID).child("history").push("hello")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM