I am building an app that has Users
, Sports Teams
and Articles
.
A user
can follow any sports team
and within that sports team
some users
will be contributors and post articles
for the followers to see.
A million users
could follow the same sports team
, but only a few users, e.g. 10, would be contributors who can post articles
about that particular sports team
.
Reading up on Firestore, I may be inclined to structure my data in the following way:
E.g. Structure:
Users
(Root Collection)- User (document)
- followingSportsTeamsIDs (map)
- User (document)
Sports Teams
(Root Collection)- Sport Team (document)
- contributingUsersIDs (map)
Posts
(Subcollection)- Post (document)
- Sport Team (document)
From my understanding if I want to perform a query to list all Sports Teams
for those that I am a contributor for, I would simply do a fetch on Sports Teams
where('contributingUsersIDs.someUserID', '==', true)
.
Question:
How are you meant to do a simple query to retrieve the list of all the Sports Teams
documents you as a particular user follow? In Datastore
I'd simply do ofy().load().keys(followingSportsTeamsIDsKeys).values()
.
Is the proper solution to simply do a fetch to retrieve all the followingSportsTeamsIDs
a user has, then if say they follow a thousand different Sports Teams
to simply do db.collection("teams").document("someTeamID").getDocument
and make a request for each ID in a for loop on the client? That seems excessive? But maybe not because Firestore
remains a persistent connection?
Or, how am I meant to restructure my data for Firestore
?