Reputation: 311
I have a question about the best way to structure my Firebase database for my iOS app. The basic structure is that there are users
and posts
. The app will open and the user
who is logged in will see all the posts
that he/she has uploaded to the database (I may update this down the road so that users can see posts of users
they follow). Is it better to have each post
have a userId
on it? Or is it better to have the an array of posts
associated to each user
?
Upvotes: 0
Views: 739
Reputation: 598837
If you can shard/partition the data so that you don't need to query a potentially very long list of that, that is always preferable with the realtime database.
So in your case, if you know that you want to show the user a list of their own posts as a starting point, it is a good idea to model that list in your database. You'd typically call this the user's feed or wall, depending on what your social network of choice is.
If you then later want to also show the posts of users they follow, you might want to store those posts in the user's wall. This type of data duplication may seem unnatural at first, but is quite common in NoSQL databases. In fact, this is the exact model that Firebase uses in its class FireFeed example.
To learn more about NoSQL data modeling, see:
Upvotes: 1