Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda