0

I have a list of chats with an array field named users_in_chat in Firebase. Is there any way I can query only the chats which contain current user id?

I tried this

database.getReference("Chats")
            .orderByChild(current_user.getUser_doc_id()).equalTo(Boolean.TRUE)
            .addListenerForSingleValueEvent(new ValueEventListener() {//Using user id as an indexing field}

but I got this error

PersistentConnection: pc_0 - Using an unspecified index. Your data will be downloaded and filtered on the client

is there an efficient way to query using a user id?

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • It looks like you have a database structure that makes it easy to find the users for a specific chat, but not to find the chats for a specific user. You'll need to add another data structure to allow that, where you map the UID to their chat IDs. So then you can load the chat IDs from there, and then load all those chats. See the answers to the questions I linked. – Frank van Puffelen Jan 26 '22 at 19:01

0 Answers0