ethan852
ethan852

Reputation: 347

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.)

Upvotes: 5

Views: 4323

Answers (1)

Jinw
Jinw

Reputation: 428

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 ).

Upvotes: 1

Related Questions