Skip to content

Commit 8a398ac

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

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,18 @@ public void countAggregateQuery() {
13661366
// [START count_aggregate_query]
13671367
Query query = db.collection("games/chess/players").whereEqualTo("online", true);
13681368
AggregateQuery countQuery = query.count();
1369-
AggregateQuerySnapshot snapshot = countQuery.get(AggregateSource.SERVER).getResult();
1370-
Log.d(TAG, "Count: " + snapshot.getCount());
1369+
countQuery.get(AggregateSource.SERVER).addOnCompleteListener(new OnCompleteListener<AggregateQuerySnapshot>() {
1370+
@Override
1371+
public void onComplete(@NonNull Task<AggregateQuerySnapshot> task) {
1372+
if (task.isSuccessful()) {
1373+
// Count fetched successfully
1374+
AggregateQuerySnapshot snapshot = task.getResult();
1375+
Log.d(TAG, "Count: " + snapshot.getCount());
1376+
} else {
1377+
Log.d(TAG, "Count failed: ", task.getException());
1378+
}
1379+
}
1380+
});;
13711381
// [END count_aggregate_query]
13721382
}
13731383
}

0 commit comments

Comments
 (0)