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

408
Vistas
Firebase v9 orderBy error: failed to fetch data TypeError: Cannot read properties of undefined (reading 'startAt')

I am new to Firebase v9 and I cannot seem to make the orderBy work, but when I tried in the Firebase console, I can see the results if I were to use the orderBy

enter image description here

error:

Failed to fetch data TypeError: Cannot read properties of undefined (reading 'startAt')

useEffect(() => {
  const retrieve = async () => {
    const querySnapshot = await getDocs(collection(db, "orders"));
    const q = query(querySnapshot, orderBy("orderCreatedAt"));
    console.log(q, "q");
    const arr = [];
    querySnapshot.forEach((doc) => {
      arr.push({
        ...doc.data(),
        id: doc.id,
      });
    });
    if (isMounted) {
      setOrders(arr);
    }
  };
}, []);

in the firebase console:

enter image description here

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

0

The query() functions accepts a Query instance for the first parameter. This can be provided by the CollectionReference returned by collection().

Your issue is that you are passing it the result of getDocs() which resolves with a QuerySnapshot.

I think you need something like this

const ordersRef = collection(db, "orders");
const q = query(ordersRef, orderBy("orderCreatedAt");
const querySnapshot = await getDocs(q);

See also

  • Perform simple and compound queries in Cloud Firestore
  • Order and limit data with Cloud Firestore

I would highly recommend using typescript to avoid these sorts of issues. It would have immediately told you that your original querySnapshot wasn't the right type for use in query().

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