Following is the structure of my Firestore database. I want to get all the documents from the collection 'products' where the 'pin_code' (is an Array) matches with the list of pin codes I have. The list of pin codes is from the collection 'addresses' which I have managed to get with the following code. But I am not able to get documents from the collection 'products' that match the list of pin codes.
Following is the code I have to get the pin code list from the collection 'addresses'
fun getPins(context: DashboardFragment) {
mFireStore.collection("addresses")
.whereEqualTo("user_id", getCurrentUserID())
.get()
.addOnSuccessListener { document ->
val codeList: MutableList<String> = mutableListOf()
for (i in document.documents) {
val code = i.toObject(Address::class.java)
code!!.user_id = i.id
codeList.add(code.pinCode)
}
context.getProductListBasedOnPin(codeList)
}
.addOnFailureListener { e ->
}
}
I tried to get the data from the collection 'products' with the following code. But with this code I can get the list of products only when my 'pin_code' is not an array. But I had to make the pin_code an array for some reason and I am not able to get the product list.
fun getProductListBasedOnPin(pinList: List<String>?) {
val mFireStore = FirebaseFirestore.getInstance()
mFireStore.collection("products")
.whereIn("pin_code", pinList!!)
.get()
.addOnSuccessListener { document ->
for (i in document.documents) {
val product = i.toObject(Product::class.java)!!
product.product_id = i.id
srchProductsList.add(product)
}
srchTempProductsList.addAll(srchProductsList)
if (newView == "ListView") {
successDashboardItemsListListView(srchTempProductsList)
} else {
successDashboardItemsList(srchTempProductsList)
}
}
.addOnFailureListener {
}
}
Can someone help me with this?
Thank you.
