hello world
hello world

Reputation: 1755

how do i grab push ID from database firebase

how do i grab the PUSH ID generated from firebase push method. I need to store this key in my App.js file for queries in the future. im not sure how to grab this key when the user is already logged in. I posted a pic of what im reffering to, to clarify

enter image description here

Upvotes: 0

Views: 45

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

To get the pushid based on the email provided, then try the following:

firebase.database().ref().child("users").orderByChild("email").equalTo(yourEmail).on("value", function (snapshot) {
 snapshot.forEach(function(childSnapshot) {
  var randomKey=childSnapshot.key;
  });
});

The snapshot is at the node users then you loop inside the keys and retrieve them using the key property

https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#key

Upvotes: 1

Related Questions