In Firebase if I'd like to create a child node with a unique ID it appears I have two options:
Push() :
Use the push() method to append data to a list in multiuser applications. The push() method generates a unique ID every time a new child is added to the specified Firebase reference. By using these auto-generated keys for each new element in the list, several clients can add children to the same location at the same time without write conflicts. The unique ID generated by push() is based on a timestamp, so list items are automatically ordered chronologically.
childByAutoId:
childByAutoId generates a new child location using a unique key and returns a FIRDatabaseReference to it. This is useful when the children of a Firebase Database location represent a list of items. The unique key generated by childByAutoId: is prefixed with a client-generated timestamp so that the resulting list will be chronologically-sorted.
Whats the difference?
Nevermind, it appears they are the same except they cater to different platforms:
Save Data on IOS
childByAutoId
: Add to a list of data. Every time you call childByAutoId, Firebase generates a unique ID, such asuser-posts/<user-id>/<unique-post-id>
.
Save Data on Web
push()
: Add to a list of data. Every time you callpush()
, Firebase generates a unique ID, such asuser-posts/<user-id>/<unique-post-id>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With