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

122
Vistas
Firebase realtime database query for specific field

I would like to query a Firebase Realtime Database to find a users account based on their Email.

enter image description here

Here is how I am doing it currently with the User's ID obviously wrong when you don't know the ID.

const userData = (await UsersDatabase.ref(`/Users/oi73WHp4T8LUCgtZzesN`).once('value')).val();

How can I query all of the users to find the account with a specific email.

Here is what the JSON Response looks like:

{
   "userData":{
      "Account Created":1647458347685,
      "Date of Birth":"01/01/1901",
      "Email":"user@domain.com",
      "Gender":"male",
      "Name":"Test Account"
   }
}

Here is the updated response from this request:

     const userData = (await UsersDatabase.ref("Users").child("userData").orderByChild("Email").equalTo("test@domain.com"));

Here is the response in Postman:

{
    "userData": "https://domain.europe-west1.firebasedatabase.app/Users/userData"
}

All help is welcome!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Assuming the email address is stored in the Email property, you can use a query to find the correct child node of Users with:

UsersDatabase
  .ref("Users")
  .orderByChild("Email")
  .equalTo("user@domain.com")
about 4 years ago · Juan Pablo Isaza Denunciar

0

In this line, you are awaiting the Reference itself - not fetching its data:

const userData = (await UsersDatabase.ref("Users").child("userData").orderByChild("Email").equalTo("test@domain.com"));

This line should be (fixed the query and shattered for readability):

const userData = (
  await UsersDatabase.ref("Users")
    .orderByChild("Email") // <-- removed .child("userData")
    .equalTo("test@domain.com")
    .once('value') // <-- this was missing
).val();

/*
userData will be:

{
  "oi73WHp4T8LUCgtZzesN": { // <- this will be random
    "Account Created":1647458347685,
    "Date of Birth":"01/01/1901",
    "Email":"test@domain.com",
    "Gender":"male",
    "Name":"Test Account"
  }
}
*/

Although I would rewrite it like this to unwrap the data:


const foundUsersQuerySnapshot = await UsersDatabase.ref("Users")
  .orderByChild("Email")
  .equalTo("test@domain.com")
  .limitToFirst(1)
  .once('value');

let userData = null;
foundUsersQuerySnapshot.forEach(childSnapshot => {
  userData = { ...childSnapshot.val(), _key: childSnapshot.key };
  return true; // <- only return first entry
});

/*
userData will either be null (not found) or:

{
  "_key": "oi73WHp4T8LUCgtZzesN",
  "Account Created":1647458347685,
  "Date of Birth":"01/01/1901",
  "Email":"test@domain.com",
  "Gender":"male",
  "Name":"Test Account"
}
*/
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