且构网

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

如何在Firestore中基于子集合文档值返回父集合?

更新时间:2023-02-14 09:58:41

除了 .data()方法之外,检索到的 doc 也具有包含CollectionReference的.parent 属性-在这种情况下,它将引用您的 Users 集合.该集合还具有一个 .parent 属性,该属性将指向您的 TeamName 文档.它的父项将指向您的 Team1 集合.

In addition to the .data() method, the retrieved doc also has a .parent property which contains a CollectionReference - in this case, it'd reference your Users collection. That collection also has a .parent property that will point to your TeamName document. It's parent will point to your Team1 collection.

使用这些文档和集合的父属性,您可以将树向上"移动到团队集合中,以在其上检索其文档.

Using these parent properties of the documents and collections, you can work your way 'up' the tree to your Team collection upon which you can retrieve its documents.