0

We are trying to create a simple chat application using Firebase as the backend. We are struggling with the right data structure to use.

So we have rooms and users. It's a many to many relation: one room can have many users as members and one user can be a member of many rooms. How do we structure this data?

If we do the following:

room {
  name: ,
  desc: ,
  members: [
    users {
     name: ,
     email: ,
     age: ,
     bio: ,
     ...
    }
  ]
}

How do we update the user details when that changes? And if we did the opposite, of having rooms a property of the users node, how do we update the rooms? I considered having another object relations with a pointer to room and a pointer to member, but I didn't find a way to use pointers in Firebase.

relations {
  user: <pointer to users>
  room: <pointer to rooms>
}

Any advice would be helpful. I have looked at various articles including Anant's Denormalizing you Database is normal, but haven't been able to solve our case.

ajuser
  • 179
  • 1
  • 5
  • 1
    I've described a few possible approaches of fanning out data changes in this answer: http://stackoverflow.com/questions/30693785/how-to-write-denormalized-data-in-firebase/30699277#30699277. My original answer on data structuring is probably also a good read: http://stackoverflow.com/questions/16638660/firebase-data-structure-and-url/16651115#16651115 – Frank van Puffelen Aug 02 '15 at 15:26
  • Although not completely, it helps me find a workaround for my problem. So thank you. Great answers on the other two questions btw! – ajuser Aug 02 '15 at 17:55
  • Great examples [here](https://www.firebase.com/docs/security/guide/user-security.html#section-revisiting-advanced-example) and [here](https://www.firebase.com/docs/web/guide/user-auth.html#section-login-demo) in the docs, including live code. Also chat apps listed in the [examples](https://www.firebase.com/docs/web/examples.html) – Kato Aug 03 '15 at 20:06

0 Answers0