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

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

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