Hi C2C community.
I’m building a social app with Firebase and had a basic question around database structuring and querying as it relates to posts and “friends” that I was hoping to get some guidance with.
Context
I have 2 collections:
-
Users
-
Posts
Custom Fields
-
Users have a field called: friends with a field type - List <Doc Reference (users)>
-
Posts have a field called: createdBy with a field type - Doc Reference (users)
Challenge
Display a feed of posts where the createdBy user is in my friends list?
My approach
Querying the posts collection only shows posts where the createdBy value is in my friends list.
Expected result
Return a list of posts only from users in my friends list
Actual result
A list of posts from all users.
Question
Is there a better way to query this type of request with Firebase? Would it be easier if friends were a subcollection of users?
Open to thoughts/suggestions.
Thanks in advance,
~Kevin