1

I am trying to query my firebase database in a way that will get me a query which I will be able use in the FirebaseRecyclerAdapter. The structure is the following:

root

--USERS

---Favorites

----{Some post IDs}

So after I get these IDs and save them in a list I want to show them in a recyclerView with all the post details. In order to do that I need to access an other portion of my DB which is the following:

root

--POSTS

---{POST_IDS}

----{POST_DETAILS}

Now lets say that the list of the favorites posts of user contains the following IDs [1,3,8].

val query: Query = housesDb.orderByKey().startAt(favPostList[0]).endAt(favPostList[favPostList.size - 1])

The problem with this query is that I also get the inbetween IDs like [2,4,5,6,7].

Is there any way to query like:

val query: Query = housesDb.orderByKey().equalTo(favPostList)

A simple solution would be to create a custom adapter but I would prefer to use the Firebase one if possible.

Nick Pampoukidis
  • 702
  • 8
  • 28
  • There's no such query. I recommend creating a custom adapter – Rosário Pereira Fernandes Dec 06 '17 at 21:21
  • Firebase Database does not have an equivalent of queries `SELECT * FROM houses WHERE id in (1,2,3)`. See https://stackoverflow.com/questions/29560088/firebase-equivalent-to-sql-where-in. Retrieving the individual items is not as slow as you may think though. See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Dec 06 '17 at 21:57

0 Answers0