In a chat app, I have a user object which is subscribed to channels (e.g. each user contains the channel ID list in its document):
User
Channels
ID 1
ID 7
I want to be able to subscribe to channels based on the user channels list (pseudo-code):
channelsCollection.documentsWhereIn("id",[1,7]).addSnapshotListener...
I can't find any way of actually achieving this, so the only solution I've been able to come up with is maintaining the subscribed users in the channel list
Channel
Users
UserId1:True
UserId7:True
...
And then subscribing with
channelsCollection.whereEqualTo("users.id",myId).addSnapshotListener...
The downside is that I feel that this is a bit fragile to maintain on the channel document, in the end it's a javascript object that could easily be overridden by some mistake. I'm looking for a more granular solution.
I was considering subcollections, but saw here that I can't query based on them yet.
I think this hasn't been answered yet because:
What's the best way to get data from collections nested in documents in Firestore? - doesn't provide a solution to extracting only user-related channels/chats
Firestore query subcollections - Mentions that I can't query based on subcollections