I want to find all the users whose phone number is contained in the list.
It's like searching *
from database where email IN phone_numbers.
This is what I am doing.
fun getUsers(persons: List<Person>?): Single<List<User>> {
return Single.create({ emitter ->
try {
val db = FirebaseFirestore.getInstance()
val userCollection = db.collection(USER_FIREBASE_TABLE)
var query: Query? = null
persons?.forEach({ person ->
query = if (null == query) userCollection
.whereEqualTo("phone", person.phone)
else query!!.whereEqualTo("phone", person.phone)
})
query?.get()?.addOnCompleteListener({ task: Task<QuerySnapshot> ->
emitter.onSuccess(task.getResult().toObjects(User::class.java))
})
} catch (exception: Exception) {
exception.printStackTrace()
emitter.onError(exception)
}
})
}
As you see I am appending whereEqualTo each time to the query. Is there any way to replace it with something like whereIn and I pass an array or collection of values to match to?