How to get firebase id

Calling push() will return a reference to the new data path, which you can use to get the value of its ID or set data to it.

The following code will result in the same data as the above example, but now we'll have access to the unique push ID that was generated:

// Generate a reference to a new location and add some data using push()
var newPostRef = postsRef.push();
// Get the unique ID generated by push()
var postID = newPostRef.key();

Documentation.


The call to push will return a Firebase reference. If you are using the Firebase 3 API, you can obtain the unique key of the pushed data from the reference's key property:

var pushedRef = firebase.database().ref('/customers').push({ email: email });
console.log(pushedRef.key);

The key for the pushed data is generated on the client - using a timestamp and random data - and is available immediately.