I am trying to fetch data from Firebase Firestore with multiple where conditions. The problem is the where conditions are to apply at different levels. `
db.collection("users")
.whereEqualTo("sex", oppositeSex)
.whereNotEqualTo("connections/likedBy", true) // this is the additional condition I need
.whereNotEqualTo("connections/dislikedBy", true) // this is the additional condition I need
.get()
.addOnCompleteListener { task ->`.....
This is the database structure
In these queries what I am trying to achieve is a way to be able to extend the path(db reference) to the child collections. I have used "/" just to show what needs to be done. How can this be achieved?
UPDATE:
private fun retrieveOppositeSexUsers() {
try {
var oppositeSex = if (currentUserSex == "Male") "Female" else "Male"
db.collection("users")
.whereEqualTo("sex", oppositeSex)
.get()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
arrlstOppositeSexUsers.clear()
try {
task.result.apply {
db.collection("users").document().collection("connections")
.whereNotEqualTo(strCurrentUserID, true).get()
.addOnCompleteListener { task ->
for (document in task.result!!) {
val userID = document.id
val name = document.data["username"].toString()
val profileImageURL =
document.data["profileImageURL"].toString()
val user = User(userID, name, profileImageURL)
arrlstOppositeSexUsers.add(user)
flingContainer.adapter = userAdpater
userAdpater!!.notifyDataSetChanged()
Log.d(TAG, document.id + " => " + document.data)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
} else {
Log.d(TAG, "Error getting documents.", task.exception)
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}