Firebase Firestore - relational data design approaches

Viewed 9517

I'm totally new to Firebase, and I'm trying to get my head round the best db model design for 'relational' data, both 1-1 and 1-many.

We are using the Firestore db (not the realtime db).

Say we have Projects which can contain many Users, and a User can be in multiple Projects

The UI needs to show a list of Users in a Project which shows things like email, firstname, lastname and department.

What is the best way to store the relationship?

  • An array of User ids in the Project document?
  • A map of Ids in the Project document?

Ive read the above approaches were recommended, but was that for realtime database? Firestore supports Sub Collections, which sound more appropriate...

If its just a map or array of Ids, how would you then retrieve the remaining data about the user? Would this have to sit in the application UI?

If its a sub collection of Users documents, is there any way to maintain data integrity? If a user changed their name, would the UI / a cloudFunction then have to update every entry of that users name in the Sub collections?

any help / pointers appreciated...

1 Answers
Related