查询多个集合中的数据 [英] Query data in multiple collections

查看:85
本文介绍了查询多个集合中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Firestore开发聊天应用程序. 我有一个用于聊天室的集合,另一个是用于用户信息的集合. 收听会议室快照时,如何检索用户数据.

这是我的数据库结构:

请帮助

解决方案

Firestore不具有跨集合的服务器端连接或投影的概念.每次读取的查询或文档只能从单个集合或具有与 NoSQL数据建模,并观看开始了解Cloud Firestore . /p>

I am developing a chat app using Firebase Firestore. I have a collection for room chat and another one for user info. How can I retrieve user data when I listen Room snapshot.

This is my database structure:

Please help

解决方案

Firestore does not have the concept of server-side joins or projections across collections. Each query or document read can only take data from a single collection, or from all collections that have the same name with collection group queries. If you need to load data from two collections, you'll need at least two reads.

So in your case you'll need to load the user data separately, typically caching it in a collection in your code to prevent loading the same user too frequently.

Another alternative is to duplicate the data that you frequently need from each user into chat documents. This type of duplication is also quite common when modeling data in NoSQL databases.

For more on these topics, I highly recommend reading NoSQL data modeling and watching getting to know Cloud Firestore.

这篇关于查询多个集合中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆