1

Filtering has to be done on the basis of Multiple attributes such as Location, Preferred Gender, etc. For this, I have used Firebase database as my backend. I am fetching data accordingly using a query string such as,

     fun populateItems() 
    {
    if (noUsersLayout == null) {
        progressLayout.visibility = View.VISIBLE
    }
    noUsersLayout.visibility = View.GONE
    progressLayout.visibility = View.VISIBLE
    val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)
    cardsQuery.addListenerForSingleValueEvent(object : ValueEventListener {
        override fun onCancelled(p0: DatabaseError) {

        }

        override fun onDataChange(p0: DataSnapshot) {
            p0.children.forEach { child ->
                val user = child.getValue(User::class.java)
                            var showUser = true
                            if (child.child(DATA_SWIPES_LEFT).hasChild(userId) ||
                                child.child(DATA_SWIPES_RIGHT).hasChild(userId) ||
                                child.child(DATA_MATCHES).hasChild(userId)){
                                showUser = false
                            }
                            if (showUser) {
                                rowItems.add(user!!)
                                cardsAdapter?.notifyDataSetChanged()
                            }

                progressLayout.visibility = View.GONE
                if (rowItems.isEmpty()) {
                    noUsersLayout.visibility = View.VISIBLE
                }

                    }

                }
            })

So how can I add multiple queries to this statement? i.e.

val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location) along with userDatabase.orderByChild(DATA_GENDER).equalTo(preferredGender)

I have tried using .also{} and .with{} but it didn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Firebase real time database does not support multiple queries. check my ans here: https://stackoverflow.com/a/57110838/5370550 – Nik Dec 13 '19 at 06:23
  • You need to Use DatabaseReference inside another DatabaseReference: refer this aswer https://stackoverflow.com/questions/41135658/how-to-perform-join-query-in-firebase – Vrushi Patel Dec 13 '19 at 06:39

0 Answers0