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

219
Vistas
How to return the total number of results on a paginated Firestore query without paying for all the reads

I'm working on a Firestore paginated query. Therefore, I would like to return the total number of results, so I can calculate the total number of pages and show a proper page navigation element.

You'll see from the docs below that they recommend you to use the last document on the queryResult to get the next page using startAfter(lastDoc). That's ok.

But how can I know the total number of results? Let's say I have 10.000 results in that query.

If I do:

const q = query(collection(db, "cities"), orderBy("population")); // WITHOUT THE limit
const querySnapshot = await getDocs(q);
const total = querySnapshot.docs.length; // I CAN READ THE TOTAL HERE

By querying the whole thing, I'm already paying for the 10.000 reads, right? Even though my user might only want to see the 1st page with 50 results, for example.

Is there a way to know the size/total of a query result, without paying for all the reads?

From Firestore docs:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Apparently this is not possible.

If you query the whole thing to know the total, you are paying for all those reads. That's a fact.

Just re-watched their official tutorial video about pagination, and there's a bunch of people in the comments complaining exactly about the lack of this feature.

You could set up Cloud Functions (with Firestore triggers) to keep track of your query sizes if you know the filters (where clause) your are going to use, but that should be cumbersome for sure.

If you are going that route, you might also just go ahead and set up a full-blown search service like ElasticSearch, Algolia or something.

Their official tutorial video on Firestore pagination:

https://www.youtube.com/watch?v=poqTHxtDXwU

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