Search code examples
androidfirebaselistenergoogle-cloud-firestore

Disable the first query snapshot when adding a snapshotListener


Firestore realtime updates documentation here

Here is the comment you can find in the documentation.

Important: The first query snapshot contains added events for all existing documents that match the query. This is because you're getting a set of changes that bring your query snapshot current with the initial state of the query. This allows you, for instance, to directly populate your UI from the changes you receive in the first query snapshot, without needing to add special logic for handling the initial state.

I understand how it can be usefull but in some case it just bother me and I'd like to know if there are any way to prevent that first query snapshot from trigerring the listener.


Solution

  • There is no way to suppress getting the initial data.

    Depending on the use-case, you may want to attach your listener to a subset of the data. E.g. if you have an append-only scenario (such as chat), you can start listening for data that was modified after "now".