File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
firestore/app/src/main/java/com/google/example/firestore Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -1362,9 +1362,28 @@ public void onComplete(@NonNull Task<Void> task) {}
1362
1362
// [END update_delete_field]
1363
1363
}
1364
1364
1365
+ public void countAggregateCollection () {
1366
+ // [START count_aggregate_collection]
1367
+ Query query = db .collection ("cities" )
1368
+ AggregateQuery countQuery = query .count ();
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
+ });
1381
+ // [END count_aggregate_collection]
1382
+ }
1383
+
1365
1384
public void countAggregateQuery () {
1366
1385
// [START count_aggregate_query]
1367
- Query query = db .collection ("games/chess/players " ).whereEqualTo ("online " , true );
1386
+ Query query = db .collection ("cities " ).whereEqualTo ("state " , "CA" );
1368
1387
AggregateQuery countQuery = query .count ();
1369
1388
countQuery .get (AggregateSource .SERVER ).addOnCompleteListener (new OnCompleteListener <AggregateQuerySnapshot >() {
1370
1389
@ Override
You can’t perform that action at this time.
0 commit comments