Skip to content

Commit 3997d38

Browse files
Update firestore/app/src/main/java/com/google/example/firestore/kotlin/DocSnippets.kt
Co-authored-by: Rosário Pereira Fernandes <[email protected]>
1 parent 8a398ac commit 3997d38

File tree

1 file changed

+10
-2
lines changed
  • firestore/app/src/main/java/com/google/example/firestore/kotlin

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,16 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
11351135
// [START count_aggregate_query]
11361136
val query = db.collection("games/halo/players").whereEqualTo("online", true)
11371137
val countQuery = query.count()
1138-
val snapshot = countQuery.get(AggregateSource.SERVER).result
1139-
Log.d(TAG, "Count: ${snapshot.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+
11401148
// [END count_aggregate_query]
11411149
}
11421150
}

0 commit comments

Comments
 (0)