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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With