Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda