Skip to content Skip to sidebar Skip to footer

How To Merge Data From Two Collections In Firestore?

I have two collections in firestore db 1. projects 2.users 'projects' has a field 'created_by' which hold the id of the user who created it. I want to fetch projects along with all

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:

  1. 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.

  2. 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:


Post a Comment for "How To Merge Data From Two Collections In Firestore?"