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

162
Views
Firebase Firestore Query v9 Works "desc" but not "asc" (indexed both)

I am trying to order by price in both directions. However, it currently only works "desc" and not "asc".

The 'direction' variable is either set to "asc" or "desc" depending on button click. I have checked - it is definitely asc or desc.

The request returns 50 items on "desc" but returns an empty array on "asc". Surely this doesn't make sense as it is the same request reading the same data just in another direction.

    const reference = await query(
      collection(firestore, "assets"),
      where("status.locked", "==", true),
      orderBy("status.price", direction),
      limit(count),
      startAfter(lastVisible?.status?.price ?? "")
    );

This is how direction is initialised: (filtering either is "High to Low" or "Low to High")

let direction = filtering === "High to Low" ? "desc" : "asc";
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As we discovered in the comments, the value of lastVisible is not correct for an ascending sort in your case.

Since you're using startAfter(lastVisible?.status?.price ?? ""), you will need to find the inverted lastVisible object when you invert the sort order. Alternatively, you can invert the logic and use endBefore instead.

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