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

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

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