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

197
Visualizações
Why Firebase query with orderByChild returns a link?

According to the docs, I use this code to get the players in ascending order:

 const db = getDatabase();
 const playersByPoints = query(
      ref(db, 'usersPoints'),
      orderByChild('points'),
    );

But when I console.log(playersByPoints) I get this:

"https://app-name.firebaseio.com/usersPoints"

Here is the database:

enter image description here

Am I missing something?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your playersByPoints here is a Query object, which when logged returns the string of the linked database reference.

You need to actually invoke the query using either get(q) or onValue(q) to get the data you are looking for.

// one-off
const playersByPointsQuery = query(
  ref(db, 'usersPoints'),
  orderByChild('points'),
);

const playersByPointsQuerySnapshot = await get(playersByPointsQuery);
const playersByPoints = [];
      
playersByPointsQuerySnapshot.forEach(childSnapshot => {
  playersByPoints.push({
    ...childSnapshot.val(),
    _key: childSnapshot.key
  });
});

// todo: do something with playersByPoints

or

// realtime listener
const playersByPointsQuery = query(
  ref(db, 'usersPoints'),
  orderByChild('points'),
);

const unsubscribe = onValue(
  playersByPointsQuery,
  {
    next: (playersByPointsQuerySnapshot) => {
      // new data available
      const playersByPoints = [];
      
      playersByPointsQuerySnapshot.forEach(childSnapshot => {
        playersByPoints.push({
          ...childSnapshot.val(),
          _key: childSnapshot.key
        });
      });
    
      // todo: do something with playersByPoints
    },
    error: (err) => {
      // error
      // todo: handle
    }
  }
);
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