Nesting Stars In Firebase Database
I find Firebase Database sample very helpful, but I noticed something which worries me a little bit. I mean in this example user can give star to the post, something like 'Like it'
Solution 1:
firebaser here
When writing the examples for our documentation, we always have to balance the need for having enough context, keeping the example small enough , and following our own best practices.
This is indeed one of the cases where we violate one of our own best practices "not nesting data". As you said: this means that a user downloading a post, gets all the UIDs of users that liked that post.
As the usage of the application scales, that may become a concern. If that is the case for your app, you should model the "users who upvoted a post" as a separate top-level node:
"posts": {
"post_id" : {
"author": "username",
"body": "Some content",
"starCount": 1
"title": "Some title",
"uid": "author_id"
}
},
"upvotes": {
"post_id" : {
"user_id_who_gave_star" : "true"
}
}
Post a Comment for "Nesting Stars In Firebase Database"