Skip to content

Commit 2389143

Browse files
jmmendiviljamesdaniels
authored andcommitted
add collectionData() to docs (#2290)
1 parent 379e192 commit 2389143

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/rxfire/docs/firestore.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ collection(db.collection('users'))
6565
.subscribe(users => { console.log(users) });
6666
```
6767

68+
### `collectionData()`
69+
The `collectionData()` function creates an observable that emits a stream of collection documents payload with optional document ID.
70+
71+
| | |
72+
|-----------------|------------------------------------------|
73+
| **function** | `collection()` |
74+
| **params** | query: `firestore.CollectionReference` | `firestore.Query`, idField?: `string` |
75+
| **import path** | `rxfire/firestore` |
76+
| **return** | `Observable<T[]>` |
77+
78+
#### TypeScript Example
79+
```ts
80+
import { collectionData } from 'rxfire/firestore';
81+
import { firestore, initializeApp } from 'firebase';
82+
import 'firebase/firestore';
83+
84+
// Set up Firebase
85+
const app = initializeApp({ /* config */ });
86+
const db = app.firestore();
87+
const davidDoc = db.doc('users/david');
88+
89+
// Seed the firestore
90+
davidDoc.set({ name: 'David' });
91+
92+
collectionData(db.collection('users'), 'uid')
93+
.subscribe(users => { console.log(users) });
94+
```
95+
6896
### `collectionChanges()`
6997
The `collectionChanges()` function creates an observable that emits the event changes on a collection. This is different than the collection function in that it does not contain the state of your application but only the individual changes. The optional `events` parameter will filter which child events populate the array.
7098

0 commit comments

Comments
 (0)