I'm developing an app on Android using Firebase that should embed a chat.
My issue is that to fetch messages, I need to query all the messages which have my uid either in sender or receiver field. This would be extremely easy to do in MySQL, but in Firebase (I must stick onto Firebase) looks kinda pain.
I cannot just filter them like that. And being receiver
and sender
fields of the object inside chat, I cannot even just filter them when I'm using a Firebase url like firebase.myapp.io/chat.
So the only possible solution in this model, is fetching all the chats and client-filtering them. This is all but good way to do this job. Also, when the message will be many, if they should, everything could become extremely slow.
So I thought about different ways to achieve the result:
- I get in chat the keys corresponding to user uid. Among the values, I get chats from user point of view, or I got the keys of my receivers as values, and inside the messages
But I don't like this very much since it can be extremely redundant, since every message should be inserted twice in the db.
Another way would be memorizing messages keys into another object, like chatmessages, and inside I got users uids as values, and as keys containing chat message keys.
What would be the best NoSQL way to manage multiple, private chat conversations?