简体   繁体   English

是否可以在 Firestore 中比较两个 collections?

[英]Is it possible to compare two collections in Firestore?

I'm developing an Android app with Java and using Firestore, It's a social.network and I have a collection with all the posts.我正在使用 Java 开发一个 Android 应用程序并使用 Firestore,它是一个 social.network,我有一个包含所有帖子的集合。 I'm trying to show only those posts that belong to the followed users, so I make a query to show all the posts ordered by timestamp, but I don't know if I can filtered them by comparing with the collection "followed" inside "User".我试图只显示属于关注用户的那些帖子,所以我查询以显示按时间戳排序的所有帖子,但我不知道是否可以通过与内部“关注”的集合进行比较来过滤它们“用户”。

The main collection "Users" has documents, each of them is a user, inside every user there is a subcollection "followed" that contains the followed users, every document is a user and the document id is the same that the User ID.主集合“Users”有文档,每个文档都是一个用户,在每个用户内部都有一个包含关注用户的子集合“followed”,每个文档都是一个用户,文档 ID 与用户 ID 相同。

The posts are stored in another main collection called Posts, so I need to compare the id User inside "Posts" documents with the id of the docs in the subcollection "followed".帖子存储在另一个名为 Posts 的主集合中,因此我需要将“Posts”文档中的 id User 与“followed”子集合中文档的 id 进行比较。 I hope somebody can help me, I spent a lot of time and I can't find anything, thank you.我希望有人能帮助我,我花了很多时间,我找不到任何东西,谢谢。

Firestore does not have the ability to "join" documents in collections as you're describing here.正如您在此处描述的那样,Firestore 无法“加入”collections 中的文档。 It's relatively straightforward in SQL (if your server has enough memory), but Firestore (and other NoSQL databases) aren't built for this, due to its distributed nature, and the way it needs to scale.它在 SQL 中相对简单(如果您的服务器有足够的内存),但 Firestore(和其他 NoSQL 数据库)不是为此而构建的,因为它的分布式特性以及它需要扩展的方式。

The only way to do what you want is to write code to read every document in every collection that would need a comparison, and also perform that comparison with the documents in memory.做你想做的唯一方法是编写代码来读取每个集合中需要比较的每个文档,并与 memory 中的文档进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM