Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imrankst1221/08b6c4cbc52c86f806325f6219431076 to your computer and use it in GitHub Desktop.
Save imrankst1221/08b6c4cbc52c86f806325f6219431076 to your computer and use it in GitHub Desktop.
Read Data From Firestore With Condition
private fun readDataFromFirestore(ageCondition: Int){
mFirestore = FirebaseFirestore.getInstance()
mFirestore.firestoreSettings = FirebaseFirestoreSettings.Builder().build()
mFirestore
.collection("student_info")
.whereLessThan("age", ageCondition)
.get()
.addOnSuccessListener { documents ->
try {
if (documents != null) {
for (document in documents) {
Log.d(TAG, "${document.id} => ${document.data}")
}
Toast.makeText(mContext, "DocumentSnapshot read successfully!", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(mContext, "No such document!", Toast.LENGTH_LONG).show()
}
}catch (ex: Exception){
Log.e(TAG, ex.message)
}
}.addOnFailureListener {
e -> Log.e(TAG, "Error writing document", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment