I'm wondering how i am able to copy the unique ID that will be generated from PUSH to the firebase database to its Child as ID object .
see image example below:
My first approach was to generate my own uniqueID, however, i believe firebase's unique ID is more reliable than creating my own.
this.afd.database.ref().child('Data/'+ MyUniqueID).set(data);
Can you Advise? Thanks
When you call push()
with no arguments, it will return a database reference at the location of the push. It has a key
property with the unique key generated on the client. You can then use that key in the object that you then write at that location. For example, in plain javascript (not angular):
var objectToPush = { data: "foo" };
var ref = parent.push();
objectToPush.id = ref.key; // add the id to the object to write
ref.set(objectToPush);