I have a group chat app. Each chat document has a node called
chatUsers:[1,2,3,4,5]
where 1-5 is a user Id on that node.
I need to pull all chats where I am a user, so I use the array-contains operator. My issue is there is also another node called archivedChat. That node tells if I archived the chat.
ie:
archivedChat:[1,2] meaning users 1 and 2 have archived this chat. I want to get all chats where I am a user and I have not archived, and then all chats I am a user and have archived.
firebase prevents using these two operators together, and I understand I can filter on the front end, but I'd need all records retrieved that. I could have 1000 chat rooms/documents, so I do not want to query the entire collection, I'd much much prefer doing 2 separate queries. Here is where I am at:
query(
roomsRef,
where(USERS_PATH, 'array-contains', currentUserId),
where(ARCHIVE_USERS_FIELD, 'not-in', [[currentUserId]]),
orderBy(LAST_UPDATED_FIELD, 'desc'),
limit(roomsPerPage),
startAfter(lastRoom)
I can think of no way to do this. Since the chat is the same whether it is archived or not, and my archived flag just shows all archived chats in a different area and effects how I display it, I really do not want to move it into another collection....
Any help?