Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!