Thore
Thore

Reputation: 1848

Can Firebase give manually added objects an unique key?

Is it possible when adding data manually to the Firebase database, through the dashboard, to let Firebase give each new object an unique key?

enter image description here

Upvotes: 5

Views: 4220

Answers (2)

Sam
Sam

Reputation: 137

To create a randomly generated key you need to use childByAutoId() This will return a Firebase reference you could use and which will return the key with it's .key property

let createAutoID = FIRDatabase.database().reference().child("orders").childByAutoId()

createAutoID.child("someOtherChild").setValue()

See documentation here

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 138944

No, you cannot. To achieve this, you need to use the push() method programmatically. This method will generate a unique key that can be saved in your database and used later in your project.

Please see official documentation regarding saving data into a Firebase database.

Hope it helps.

Upvotes: 6

Related Questions