@@ -34,6 +34,7 @@ class FirestoreSnippets extends DocSnippet {
34
34
getStarted_readData ();
35
35
dataModel_references ();
36
36
dataModel_subCollections ();
37
+ getDataOnce_getAllDocumentsInASubcollection ();
37
38
}
38
39
39
40
void getStarted_addData () async {
@@ -453,31 +454,47 @@ class FirestoreSnippets extends DocSnippet {
453
454
void getDataOnce_multipleDocumentsFromACollection () {
454
455
// [START get_data_once_multiple_documents_from_a_collection]
455
456
db.collection ("cities" ).where ("capital" , isEqualTo: true ).get ().then (
456
- (querySnapshot) {
457
- print ("Successfully completed" );
458
- for (var docSnapshot in querySnapshot.docs) {
459
- print ('${docSnapshot .id } => ${docSnapshot .data ()}' );
460
- }
461
- },
462
- onError: (e) => print ("Error completing: $e " ),
463
- );
457
+ (querySnapshot) {
458
+ print ("Successfully completed" );
459
+ for (var docSnapshot in querySnapshot.docs) {
460
+ print ('${docSnapshot .id } => ${docSnapshot .data ()}' );
461
+ }
462
+ },
463
+ onError: (e) => print ("Error completing: $e " ),
464
+ );
464
465
// [END get_data_once_multiple_documents_from_a_collection]
465
466
}
466
467
467
468
void getDataOnce_getAllDocumentsInACollection () {
468
469
// [START get_data_once_get_all_documents_in_a_collection]
469
470
db.collection ("cities" ).get ().then (
470
- (querySnapshot) {
471
- print ("Successfully completed" );
472
- for (var docSnapshot in querySnapshot.docs) {
473
- print ('${docSnapshot .id } => ${docSnapshot .data ()}' );
474
- }
475
- },
476
- onError: (e) => print ("Error completing: $e " ),
477
- );
471
+ (querySnapshot) {
472
+ print ("Successfully completed" );
473
+ for (var docSnapshot in querySnapshot.docs) {
474
+ print ('${docSnapshot .id } => ${docSnapshot .data ()}' );
475
+ }
476
+ },
477
+ onError: (e) => print ("Error completing: $e " ),
478
+ );
478
479
// [END get_data_once_get_all_documents_in_a_collection]
479
480
}
480
481
482
+ void getDataOnce_getAllDocumentsInASubcollection () {
483
+ // [START get_data_once_get_all_documents_in_a_subcollection]
484
+ // [START firestore_query_subcollection]
485
+ db.collection ("cities" ).doc ("SF" ).collection ("landmarks" ).get ().then (
486
+ (querySnapshot) {
487
+ print ("Successfully completed" );
488
+ for (var docSnapshot in querySnapshot.docs) {
489
+ print ('${docSnapshot .id } => ${docSnapshot .data ()}' );
490
+ }
491
+ },
492
+ onError: (e) => print ("Error completing: $e " ),
493
+ );
494
+ // [END firestore_query_subcollection]
495
+ // [END get_data_once_get_all_documents_in_a_subcollection]
496
+ }
497
+
481
498
void getDataOnce_listSubCollections () {
482
499
// [START get_data_once_list_sub_collections]
483
500
// Not currently available in Dart SDK
@@ -807,27 +824,20 @@ class FirestoreSnippets extends DocSnippet {
807
824
void aggregationQuery_count () {
808
825
// [START count_aggregate_collection]
809
826
// Returns number of documents in users collection
810
- db
811
- .collection ("users" )
812
- .count ()
813
- .then (
814
- (res) => print (res.data ().count),
815
- onError: (e) => print ("Error completing: $e " ),
816
- );
827
+ db.collection ("users" ).count ().then (
828
+ (res) => print (res.data ().count),
829
+ onError: (e) => print ("Error completing: $e " ),
830
+ );
817
831
// [END count_aggregate_collection]
818
832
}
819
833
820
834
void aggregationQuery_count2 () {
821
835
// [START count_aggregate_query]
822
836
// This also works with collectionGroup queries.
823
- db
824
- .collection ("users" )
825
- .where ("age" , isGreaterThan: 10 )
826
- .count ()
827
- .then (
828
- (res) => print (res.data ().count),
829
- onError: (e) => print ("Error completing: $e " ),
830
- );
837
+ db.collection ("users" ).where ("age" , isGreaterThan: 10 ).count ().then (
838
+ (res) => print (res.data ().count),
839
+ onError: (e) => print ("Error completing: $e " ),
840
+ );
831
841
// [END count_aggregate_query]
832
842
}
833
843
0 commit comments