Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda