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

120
Visualizações
orderBy and where clause not working together in firestore

I am using a where clause on my firestore query to filter based on an attribute type and then ordering them using the orderBy to order them by time.

 const tradesRef = firebase
    .firestore()
    .collection("cex-trades")
    .orderBy("time", "desc")
    .limit(16);

  useEffect(() => {
    if (filter === "5m") {
      tradesRef
        .where("type", "==", "fifteenMinutes")
        .get()
        .then((collections) => {
          const tradesData = collections.docs.map((trade) => trade.data());
          const lastDoc = collections.docs[collections.docs.length - 1];
          const firstDoc = collections.docs[collections.docs.length - 16];
          setTrades(tradesData);
          setFirstTrade(firstDoc);
          setLastTrades(lastDoc);
        })
        .catch((error) => {
          console.error(error);
        });
    }
}, [filter]);

When I run my code, I am getting this error:

FirebaseError: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/whaletracer-432e8/firestore/indexes?create_composite=ClRwcm9qZWN0cy93aGFsZXRyYWNlci00MzJlOC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvY2V4LXRyYWRlcy9pbmRleGVzL18QARoICgR0eXBlEAEaCAoEdGltZRACGgwKCF9fbmFtZV9fEAI

I followed the link and created an index as followed: updated index

After creating the index, I am still getting the same error. Any idea how to solve the issue?

about 4 years ago · Juan Pablo Isaza
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