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

240
Views
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 answers
Answer question

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