Skip to content

feat(firestore): Support Firestore Collection Group Queries #2066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 21, 2019
19 changes: 19 additions & 0 deletions docs/firestore/querying-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,23 @@ export class AppComponent {
}
```

## Collection Group Queries

To query across collections and sub-collections with the same name anywhere in Firestore, you can use collection group queries.

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/**/...`):

```ts
constructor(private afs: AngularFirestore) { }

ngOnInit() {
...
// Get all the user's comments, no matter how deeply nested
this.comments$ = afs.collectionGroup('Comments', ref => ref.where('user', '==', userId))
.valueChanges({ idField });
}
```

`collectionGroup` returns an `AngularFirestoreCollectionGroup` which is similar to `AngularFirestoreCollection` but as it has no set reference there are no data operation methods such as `add`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this a bit tough to interpret on the first pass.

Maybe something like "... similar to AngularFirestoreCollection. The main difference is that AngularFirestoreCollectionGroup has no data operation methods such as add because it doesn't have a unique(?concrete?) reference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like concrete.


### [Next Step: Getting started with Firebase Authentication](../auth/getting-started.md)
Loading