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

125
Vistas
query from firebase realtime database

I am trying to get filtered data from my realtime database. In this example I want to get only these once with a specific uid:

enter image description here

I tried to get the data with the snippet from the firebase docs:

const db = getDatabase();
const auth = getAuth();
    
const myUserId = auth.currentUser.uid;
const myOffersRef = query(ref(db, 'allOffers/'), orderByChild('uid'), startAt(user.uid));

But how do I get the data from the const myOffersRef?

Thank you!

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

0

As shown in the documentation on reading data, you can use get to get the data at a path or for a query.

const myOffersRef = query(ref(db, 'allOffers/'), orderByChild('uid'), equalTo(user.uid));

get(myOffersRef).then((snapshot) => {
  snapshot.forEach((child) => {
    console.log(child.key, child.val().uid);
  });
}).catch((error) => {
  console.error(error);
});

Note that I also changed startAt to equalTo, as you likely only want the nodes that match the UID, not the slide of nodes starting from the first match (which is what startAt does).

The forEach is needed since a query can potentially have multiple results, so the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.

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