Created
May 13, 2019 07:52
-
-
Save imrankst1221/08b6c4cbc52c86f806325f6219431076 to your computer and use it in GitHub Desktop.
Read Data From Firestore With Condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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