206
206
207
207
### Change streams
208
208
209
- Change streams exist in replica set and cluster systems and tell you about changes to collections.
210
- They work like endless cursors.
211
- The special thing about the change streams is that they are resumable. In the case of a resumable error,
212
- no exception is made, but the cursor is re-scheduled at the last successful location.
213
- The following example will never stop,
214
- so it is a good idea to use a process for change streams.
209
+ Change streams are available in replica set and sharded cluster deployments
210
+ and tell you about changes to documents in collections. They work like endless
211
+ cursors.
212
+
213
+ The special thing about change streams is that they are resumable: in case of
214
+ a resumable error, no exception is propagated to the application, but instead
215
+ the cursor is re-scheduled at the last successful location.
216
+
217
+ The following example will never stop, thus it is a good idea to use a process
218
+ for reading from change streams:
215
219
216
220
``` elixir
217
221
seeds = [" hostname1.net:27017" , " hostname2.net:27017" , " hostname3.net:27017" ]
@@ -220,7 +224,7 @@ cursor = Mongo.watch_collection(top, "accounts", [], fn doc -> IO.puts "New Tok
220
224
cursor |> Enum .each (fn doc -> IO .puts inspect doc end )
221
225
```
222
226
223
- An example with a spawned process that sends message to the monitor process:
227
+ An example with a spawned process that sends messages to the monitor process:
224
228
225
229
``` elixir
226
230
def for_ever (top, monitor) do
231
235
spawn (fn -> for_ever (top, self ()) end )
232
236
```
233
237
234
- For more information see
238
+ For more information see:
235
239
236
240
* [ Mongo.watch_collection] ( https://hexdocs.pm/mongodb_driver/Mongo.html#watch_collection/5 )
237
241
0 commit comments