You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(db): updating the querying docs for the new API (#1170)
* docs(db): updating the querying docs for the new API
* docs(db): cleanup some of the formatting
* docs(db): kill unneeded quote character
* docs(db): adding a clear filter + show all results first
* docs(db): allow null in the filterBy example
<sup>2</sup> The Firebase SDK supports an optional `key` parameter for [`startAt`](https://firebase.google.com/docs/reference/js/firebase.database.Reference#startAt), [`endAt`](https://firebase.google.com/docs/reference/js/firebase.database.Reference#endAt), and [`equalTo`](https://firebase.google.com/docs/reference/js/firebase.database.Reference#equalTo) when ordering by child, value, or priority. You can specify the `key` parameter using an object literal that contains the `value` and the `key`. For example: `startAt: { value: 'some-value', key: 'some-key' }`.
37
30
31
+
To learn more about how sorting and ordering data works in Firebase, check out the Firebase documentation on [working with lists of data](https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data).
32
+
38
33
## Invalid query combinations
39
34
40
35
**Queries can only be ordered by one method.** This means you can only specify
41
36
`orderByChild`, `orderByKey`, `orderByPriority`, or `orderByValue`.
42
37
43
38
```ts
44
39
// WARNING: Do not copy and paste. This will not work!
You can only use `limitToFirst` or `limitToLast`, but not both in combination.
55
44
56
45
```ts
57
46
// WARNING: Do not copy and paste. This will not work!
58
-
const queryObservable =db.list('/items', {
59
-
query: {
60
-
limitToFirst: 10,
61
-
limitToLast: 100,
62
-
}
63
-
});
47
+
ref.limitToFirst(10).limitToLast(100)
64
48
```
65
49
66
50
## Creating a query with observable values
67
51
68
-
Rather than specifying regular values, observables can be used to dynamically
69
-
re-run queries when the observable emits a new value.
70
-
71
-
This is the magic of AngularFire2.
52
+
To enable dynamic queries one should lean on RxJS Operators like `switchMap`.
72
53
73
54
An RxJS Subject is imported below. A Subject is like an Observable, but can multicast to many Observers. Subjects are like EventEmitters: they maintain a registry of many listeners. See, [What is a Subject](http://reactivex.io/rxjs/manual/overview.html#subject) for more information.
74
55
56
+
When we call [`switchMap` on the Subject](https://www.learnrxjs.io/operators/transformation/switchmap.html), we cap map each value to a new Observable; in this case a database query.
57
+
75
58
```ts
76
-
const subject =newSubject(); // import {Subject} from 'rxjs/Subject';
0 commit comments