Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Firebase whats the difference between push and childByAutoId

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?

like image 460
7hacker Avatar asked Jun 29 '16 18:06

7hacker


1 Answers

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 as user-posts/<user-id>/<unique-post-id>.

Save Data on Web

push() : Add to a list of data. Every time you call push(), Firebase generates a unique ID, such as user-posts/<user-id>/<unique-post-id>.

like image 104
7hacker Avatar answered Sep 23 '22 07:09

7hacker