Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Get Key Value Given Other Key Value in FireBase

I am trying to find a way to find the value of the id given the email.

For example, If I had email2@gmail.com, It would give me the ID 108454568498950432898.

All emails are unique and there will be no repetition of emails.

This is my user tree:

enter image description here

Note: In the image it says email2 instead of email2@gmail.com. Ignore this

Here's my code so far: (Code won't run obviously but it's easier to enter code using the embed)

var users;
var givenEmail = "email2@gmail.com";
var neededID;

var dataRef = firebase.database().ref('users');
dataRef.on('value', (snapshot) => {
    const data = snapshot.val();
    users = data;
});

var usersArray = Object.keys(users);

for(i = 0; i < usersArray.length; i++) {
    if(users[i].email == givenEmail) {
        neededID = i;
        break;
    }
}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Well, I think you are almost there.

users[i].email

you can retrieve the email using this method, and similarly you can do it with id too

users[i].id

Please note that you wanted to find email2@gmail.com but your firebase only have email2

Maybe you would want to change that

about 4 years ago · Juan Pablo Isaza Report

0

I recommend using a query to perform the filtering on the server, instead of downloading the entire users node and filtering in your application code as you now do.

var givenEmail = "email2@gmail.com";

var dataRef = firebase.database().ref('users');
var query = dataRef.orderByChild('email').equalTo(givenEmail);
dataRef.once('value', (snapshot) => {
    snapshot.forEach((userSnapshot) => {
        console.log(userSnapshot.val().id);
    });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!