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
Copy file name to clipboardexpand all lines: docs/manual/database/live-query.md
+86-11
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Listening to real-time`db.liveQuery
1
+
# Listening to real-time`db.liveQuery`
2
2
You can listen / subscribe to changes happening in your app's data in real time by simply calling `db.liveQuery` on the frontend. Here's a code snippet to do this:
**type:** Type of operation due to which the `onSnapshot` is called. It can have one of the following values:
134
143
-**initial** - Called only once for the initial data on successful subscription
135
-
-**write** - Whenever any data is added or updated
144
+
-**insert** - Whenever any data is added
145
+
-**update** - Whenever any data is updated
136
146
-**delete** - Whenever any data is deleted
147
+
**changedDoc:** The doc that changed.
137
148
138
149
`onError` function is called with the `error` if there was any error subscribing to data.
139
150
140
151
As you would have noticed the `subscribe` function returns an `unsubscribe` function. You should call this function whenever you want to unsubscribe to the changes.
141
152
153
+
## Setting the liveQuery options:
154
+
You can set the liveQuery options using the `options()` function.
155
+
The function helps to set `changesOnly` to true or false (default).
156
+
If `changesOnly` is false, it caches the docs. `onSnapshot` will be called with all 3 parameters set.
157
+
If `changesOnly` is true, it does not cache the docs and also ignores the initial values. `onSnapshot` will be called with only the last 2 parameters set.
158
+
159
+
Here's a code snippet to do this:
160
+
161
+
<divclass="row tabs-wrapper">
162
+
<divclass="col s12"style="padding:0">
163
+
<ul class="tabs">
164
+
<li class="tab col s2"><a class="active" href="#live-query-options-js">Javascript</a></li>
165
+
<li class="tab col s2"><a href="#live-query-options-java">Java</a></li>
166
+
<li class="tab col s2"><a href="#live-query-options-python">Python</a></li>
167
+
<li class="tab col s2"><a href="#live-query-options-golang">Golang</a></li>
0 commit comments