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

244
Vistas
How to listen to real-time updates in Firestore without getting all the documents?

This code listen to the updates from the given query, and get all the documents immediately.

import { collection, query, where, onSnapshot } from "firebase/firestore";

const q = query(collection(db, "posts"), where("character_count", ">", 1));

onSnapshot(q, (querySnapshot) => {
  querySnapshot.forEach((doc) => {
      console.log(doc.data());
  });
});

I want to get all events from query "where character_count > 1", but without immediately getting all the documents from the collection posts which could fetch a millions of documents...

Is it possible to do this in FireStore?

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

0

Firestore listeners will always get all documents matching the query in the first callback. There is no way to change that behavior. You can't tell it to only give you "new" documents.

If you want to introduce the concept of "new" documents, you will need to add a timestamp field to documents in the collection, and use that as a filter in the query. The problem is that the query will also have to provide a timestamp in the client app to use for filtering, and that timestamp is going to be dependent on the clock on that machine, which might not match the clock being used by the software that's adding the documents.

In short, Firestore isn't really designed to be a messaging service that lets clients understand what new "events" (documents) are passing through the system. There are other cloud products that do that, which are typically called message queues or pub/sub.

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