![](/img/trans.png)
[英]why Creating multiple documents at same time with subCollection appear as Italic?
[英]Can I retrieve documents of same subcollection in different collections with the same name, using Firestore?
我正在开发一个 Android 应用程序,我使用 Firestore 来存储我的数据。 我有一个Users集合,每个用户都有一个名为Posts的子集合。 有什么方法可以检索所有用户的所有帖子以在我的应用程序提要中显示它们吗?
有什么方法可以检索所有用户的所有帖子以在我的应用程序提要中显示它们吗?
当然是啦。 您需要使用集合组查询:
使用集合组查询从集合组而不是从单个集合中检索文档。 在代码中应该是这样的:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
rootRef.collectionGroup("Posts").get().addOnCompleteListener(/* ... */);
使用上面的代码,您将能够获取存在于所有名为Posts
的子集合中的所有Post
对象。
您将希望使用集合组查询从所有子集合中获取同名的所有文档。 例如:
db.collectionGroup("Posts").get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.