Skip to content Skip to sidebar Skip to footer

How Do I Listen For Changes For All Documents In A Subcollection In Firestore?

I want to listen to changes in the chats collection for all docs in the messages collection but can't find a method that'll allow that. updateUsersListOnChange = loadUsersCallbac

Solution 1:

What you're describing is known as a collection group query, a query across a group of collections.

db.collectionGroup("chats").onSnapshot(() => {
    loadUsersCallback();
});

This will load the documents from all collections named chats across your entire database. There is no way to indicate a path, so you'll want to ensure that your collection names are unique enough to allow you to identify the right by by their name alone.

For more on this, see the documentation on collection group queries.


Post a Comment for "How Do I Listen For Changes For All Documents In A Subcollection In Firestore?"