Setting custom key when pushing new data to firebase database

Victor Davis Lenz picture Victor Davis Lenz · May 27, 2016 · Viewed 53.9k times · Source

Well, I am new to Firebase and I want to have my own keys while pushing new data to database.

Problem:

FireBase.push().setValue(mapped_values);

This gives structure like below:

 database output

How can I create my own custom key there? Such as username or something.

Answer

Frank van Puffelen picture Frank van Puffelen · May 27, 2016

Calling push() will generate a key for you.

If instead you use child(), you can determine they key/path yourself.

ref.child("Victor").setValue("setting custom key when pushing new data to firebase database");