Skip to content

Commit c34c0f3

Browse files
authored
feat(firestore): Support Firestore Collection Group Queries (#2066)
1 parent 8a33826 commit c34c0f3

File tree

10 files changed

+625
-7
lines changed

10 files changed

+625
-7
lines changed

docs/firestore/querying-collections.md

+19
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,23 @@ export class AppComponent {
180180
}
181181
```
182182

183+
## Collection Group Queries
184+
185+
To query across collections and sub-collections with the same name anywhere in Firestore, you can use collection group queries.
186+
187+
Collection Group Queries allow you to have a more nested data-structure without sacrificing performance. For example, we could easily query all comments a user posted; even if the comments were stored as a sub-collection under `Articles/**` or even nested deeply (`Articles/**/Comments/**/Comments/**/...`):
188+
189+
```ts
190+
constructor(private afs: AngularFirestore) { }
191+
192+
ngOnInit() {
193+
...
194+
// Get all the user's comments, no matter how deeply nested
195+
this.comments$ = afs.collectionGroup('Comments', ref => ref.where('user', '==', userId))
196+
.valueChanges({ idField });
197+
}
198+
```
199+
200+
`collectionGroup` returns an `AngularFirestoreCollectionGroup` which is similar to `AngularFirestoreCollection`. The main difference is that `AngularFirestoreCollectionGroup` has no data operation methods such as `add` because it doesn't have a concrete reference.
201+
183202
### [Next Step: Getting started with Firebase Authentication](../auth/getting-started.md)

0 commit comments

Comments
 (0)