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

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

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 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