How To Merge Data From Two Collections In Firestore?
Solution 1:
If the code works for your use-cases, it is probably the right approach for you. Since Firestore doesn't support server-side joins, doing this client-side join is a common approach.
A few considerations though:
You're using a
get
to get both the projects and the users, which means you get the data only once. There is no problem with that, but I always recommend double-checking if you shouldn't listen for real time updates. There's no hard rule on when this is better, so just consider what the advantages and disadvantages for your users and codebase may be.Consider how much user data you really need, and whether it's worth it to duplicate this user data that you need under each project. If you duplicate the data, you won't need to perform the nested reads/client-side join. You're essentially storing more data, and complicating your write operations, to get a more scaleable read operation, and simpler code there.
When you new to NoSQL it is often hard to get to grips with the new data model. In that case I recommend checking out:
- NoSQL data modeling.
- Getting to know Cloud Firestore.
- Firebase for SQL developers (even though it's for the Firebase Realtime Database, it's still a great resource for learning about NoSQL in general).
Post a Comment for "How To Merge Data From Two Collections In Firestore?"