且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Firestore中的子集合中侦听所有文档的更改?

更新时间:2023-02-14 10:51:31

您所描述的内容称为集合组查询,即跨一组集合的查询.

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

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

这将从整个数据库中的所有名为 chats 的集合中加载文档.无法指示路径,因此您将要确保您的收藏名称足够独特,以使您可以仅通过其名称来识别权利.

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.