@@ -820,6 +820,65 @@ function listenErrors(db) {
820
820
// [END listen_errors]
821
821
}
822
822
823
+ function collectionGroupQuery ( db ) {
824
+ // [START collection_group_query_data_setup]
825
+ var citiesRef = db . collection ( 'cities' ) ;
826
+
827
+ var landmarks = Promise . all ( [
828
+ citiesRef . doc ( 'SF' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
829
+ name : 'Golden Gate Bridge' ,
830
+ type : 'bridge'
831
+ } ) ,
832
+ citiesRef . doc ( 'SF' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
833
+ name : 'Legion of Honor' ,
834
+ type : 'museum'
835
+ } ) ,
836
+ citiesRef . doc ( 'LA' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
837
+ name : 'Griffith Park' ,
838
+ type : 'park'
839
+ } ) ,
840
+ citiesRef . doc ( 'LA' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
841
+ name : 'The Getty' ,
842
+ type : 'museum'
843
+ } ) ,
844
+ citiesRef . doc ( 'DC' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
845
+ name : 'Lincoln Memorial' ,
846
+ type : 'memorial'
847
+ } ) ,
848
+ citiesRef . doc ( 'DC' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
849
+ name : 'National Air and Space Museum' ,
850
+ type : 'museum'
851
+ } ) ,
852
+ citiesRef . doc ( 'TOK' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
853
+ name : 'Ueno Park' ,
854
+ type : 'park'
855
+ } ) ,
856
+ citiesRef . doc ( 'TOK' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
857
+ name : 'National Museum of Nature and Science' ,
858
+ type : 'museum'
859
+ } ) ,
860
+ citiesRef . doc ( 'BJ' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
861
+ name : 'Jingshan Park' ,
862
+ type : 'park'
863
+ } ) ,
864
+ citiesRef . doc ( 'BJ' ) . collection ( 'landmarks' ) . doc ( ) . set ( {
865
+ name : 'Beijing Ancient Observatory' ,
866
+ type : 'museum'
867
+ } )
868
+ ] ) ;
869
+ // [END collection_group_query_data_setup]
870
+ landmarks . then ( ( l ) => console . log ( l ) ) ;
871
+
872
+ // [START collection_group_query]
873
+ let museums = db . collectionGroup ( 'landmarks' ) . where ( 'type' , '==' , 'museum' ) ;
874
+ museums . get ( ) . then ( function ( querySnapshot ) {
875
+ querySnapshot . forEach ( function ( doc ) {
876
+ console . log ( doc . id , ' => ' , doc . data ( ) ) ;
877
+ } ) ;
878
+ } ) ;
879
+ // [end collection_group_query]
880
+ }
881
+
823
882
// ============================================================================
824
883
// https://firebase.google.com/docs/firestore/query-data/query-cursors
825
884
// ============================================================================
@@ -1121,4 +1180,8 @@ describe('Firestore Smoketests', () => {
1121
1180
it ( 'should delete the whole collection' , ( ) => {
1122
1181
return deleteCollection ( db , 'cities' , 50 ) ;
1123
1182
} ) ;
1183
+
1184
+ it ( 'should find all museums when querying a collection group' , ( ) => {
1185
+ return collectionGroupQuery ( ) ;
1186
+ } ) ;
1124
1187
} ) ;
0 commit comments