Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not generate unique ID when using push method in Firebase?

I'm trying to push new data into Firebase but it keeps generating an unique ID and an extra child node for me. How can I stop generating the ID and extra node or is there another way to push data into Firbase? My dataset is given and I just need to dump the dataset into the db. (But I'm slowly updating this given dataset.)

like image 905
ethankong113 Avatar asked Nov 09 '22 12:11

ethankong113


1 Answers

Firease always generates the unique id when using the push method. You can use it as a key or as a parent node. This post describes push in more detail. https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html

You should use set to publish new data to firebase if push doesn't fit your use case. There is also an update method as set will overwrite any data in the given path.

https://firebase.google.com/docs/database/web/save-data

I generally use set for new data, or if I change how I have my data structured, or if I am appending new data in a path, update to make changes to fields for a dataset, and push for sets of data that I want organized in a list by time( i.e. Chat message log ).

like image 167
Jinw Avatar answered Jan 04 '23 02:01

Jinw