Skip to content

Commit 0bbdbf6

Browse files
committed
Add simple query
1 parent 3af7ad2 commit 0bbdbf6

File tree

1 file changed

+18
-1
lines changed
  • firestore/app/src/main/java/com/google/example/firestore/kotlin

1 file changed

+18
-1
lines changed

firestore/app/src/main/java/com/google/example/firestore/kotlin/DocSnippets.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,26 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
11311131
// [END update_delete_field]
11321132
}
11331133

1134+
fun countAggregateCollection() {
1135+
// [START count_aggregate_collection]
1136+
val query = db.collection("cities")
1137+
val countQuery = query.count()
1138+
countQuery.get(AggregateSource.SERVER).addOnCompleteListener { task ->
1139+
if (task.isSuccessful) {
1140+
// Count fetched successfully
1141+
val snapshot = task.result
1142+
Log.d(TAG, "Count: ${snapshot.count}")
1143+
} else {
1144+
Log.d(TAG, "Count failed: ", task.getException())
1145+
}
1146+
}
1147+
1148+
// [END count_aggregate_collection]
1149+
}
1150+
11341151
fun countAggregateQuery() {
11351152
// [START count_aggregate_query]
1136-
val query = db.collection("games/halo/players").whereEqualTo("online", true)
1153+
val query = db.collection("cities").whereEqualTo("state", "CA")
11371154
val countQuery = query.count()
11381155
countQuery.get(AggregateSource.SERVER).addOnCompleteListener { task ->
11391156
if (task.isSuccessful) {

0 commit comments

Comments
 (0)