ios – Listening to one added document in Firestore – Swift



I’m listening to only one added document in a collection.

No, you’re not. You’re attaching a snapshot listener to a collection and not to a single document:

  .collection("Collection") //👈
  .addSnapshotListener(/* ... */)

This means that you’re listening for real-time updates for each operation that takes place inside the entire sub-collection called “Collection”.

What you’re basically doing, you’re saying, hey Firestore, give me all documents that exist in that sub-collection and keep the listener alive. This listener will be invoked every time a document in that collection changes over time.

If you want to listen to a single document, then you should add a call to .document() and pass a specific document ID:

  .document("someDocumentId") //👈
  .addSnapshotListener(/* ... */)

In this way, you’ll only be notified about the changes to a single document.