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

157
Vistas
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 Respuestas
Responde la pregunta

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