@@ -55,6 +55,13 @@ Change Stream Examples
55
55
The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
56
56
<http://mongoc.org/libmongoc/current/tutorial.html#making-a-connection/>`__
57
57
that contains an ``inventory`` collection.
58
+
59
+ - id: ruby
60
+ content: |
61
+ The examples below assume that you have `connected to a MongoDB replica set and have accessed a database
62
+ <https://docs.mongodb.com/ruby-driver/master/tutorials/ruby-driver-create-client/>`_
63
+ that contains an ``inventory`` collection.
64
+
58
65
59
66
Open A Change Stream
60
67
--------------------
@@ -104,6 +111,16 @@ as long as a connection to the MongoDB deployment remains open *and* the collect
104
111
:dedent: 0
105
112
:start-after: Start Changestream Example 1
106
113
:end-before: End Changestream Example 1
114
+
115
+ - id: ruby
116
+ content: |
117
+ .. class:: copyable-code
118
+
119
+ .. literalinclude:: /driver-examples/change_stream_examples_spec.rb
120
+ :language: ruby
121
+ :dedent: 4
122
+ :start-after: Start Changestream Example 1
123
+ :end-before: End Changestream Example 1
107
124
108
125
In order to retrieve the data change event notifications, iterate
109
126
the change stream ``cursor``.
@@ -147,7 +164,13 @@ Lookup Full Document for Update Operations
147
164
To return the most current majority-committed version of the updated
148
165
document, pass ``"FullDocument = ChangeStreamFullDocumentOption.UpdateLookup"`` to the
149
166
:method:`collection.Watch()` method.
150
-
167
+
168
+ - id: ruby
169
+ content: |
170
+ By default, change streams only return the delta of fields during the update operation.
171
+ To return the most current majority-committed version of the updated
172
+ document, pass ``full_document: 'updateLookup'`` to the
173
+ :method:`watch()` method.
151
174
152
175
If there are one or more majority-committed operations that modified the
153
176
updated document *after* the update operation but *before* the lookup, the
@@ -206,6 +229,16 @@ update operation.
206
229
:dedent: 0
207
230
:start-after: Start Changestream Example 2
208
231
:end-before: End Changestream Example 2
232
+
233
+ - id: ruby
234
+ content: |
235
+ .. class:: copyable-code
236
+
237
+ .. literalinclude:: /driver-examples/change_stream_examples_spec.rb
238
+ :language: php
239
+ :dedent: 4
240
+ :start-after: Start Changestream Example 2
241
+ :end-before: End Changestream Example 2
209
242
210
243
See :ref:`change-stream-output` for more information on the change stream
211
244
response document format.
@@ -268,16 +301,18 @@ response document format.
268
301
Resume a Change Stream
269
302
----------------------
270
303
271
- Each change stream response document has an ``_id`` field that contains a
272
- document containing a resume token. The ``resumeToken`` includes the change
273
- stream notification id. You can use the ``resumeToken`` document to resume
274
- notification after a specific notification.
304
+
275
305
276
306
.. tabs-drivers::
277
307
278
308
tabs:
279
309
- id: python
280
310
content: |
311
+ Each change stream response document has an ``_id`` field that contains a
312
+ document containing a resume token. The ``resumeToken`` includes the change
313
+ stream notification id. You can use the ``resumeToken`` document to resume
314
+ notification after a specific notification.
315
+
281
316
In the example below, the ``resumeAfter`` modifier takes a parameter that must resolve to a resume
282
317
token. Passing the ``resumeToken`` to the ``resumeAfter`` modifier directs
283
318
the change stream to attempt to resume notifications starting at the
@@ -293,6 +328,11 @@ notification after a specific notification.
293
328
294
329
- id: java-sync
295
330
content: |
331
+ Each change stream response document has an ``_id`` field that contains a
332
+ document containing a resume token. The ``resumeToken`` includes the change
333
+ stream notification id. You can use the ``resumeToken`` document to resume
334
+ notification after a specific notification.
335
+
296
336
In the example below, the ``resumeAfter()`` method takes a parameter that must resolve to a resume
297
337
token. Passing the ``resumeToken`` to the ``resumeAfter()`` method directs
298
338
the change stream to attempt to resume notifications starting at the
@@ -308,6 +348,11 @@ notification after a specific notification.
308
348
309
349
- id: csharp
310
350
content: |
351
+ Each change stream response document has an ``_id`` field that contains a
352
+ document containing a resume token. The ``resumeToken`` includes the change
353
+ stream notification id. You can use the ``resumeToken`` document to resume
354
+ notification after a specific notification.
355
+
311
356
In the example below, the ``resumeToken`` is retrieved from the last change stream document
312
357
and passed to the ``Watch()`` method as an option. Passing the ``resumeToken``
313
358
to the ``Watch()`` method directs
@@ -324,6 +369,11 @@ notification after a specific notification.
324
369
325
370
- id: c
326
371
content: |
372
+ Each change stream response document has an ``_id`` field that contains a
373
+ document containing a resume token. The ``resumeToken`` includes the change
374
+ stream notification id. You can use the ``resumeToken`` document to resume
375
+ notification after a specific notification.
376
+
327
377
In the example below, the ``resumeAfter`` option is appended to the stream options
328
378
to recreate the stream after it has been destroyed. Passing the ``_id`` to
329
379
the change stream attempts to resume notifications starting at the
@@ -336,6 +386,25 @@ notification after a specific notification.
336
386
:dedent: 0
337
387
:start-after: Start Changestream Example 3
338
388
:end-before: End Changestream Example 3
389
+
390
+ - id: ruby
391
+ content: |
392
+ Each change stream response document has an ``_id`` field which can be passed
393
+ to the ``watch()`` method, indicating to the method at what point in the
394
+ iteration of the change stream it should resume.
395
+
396
+ In the example below, the ``resumeAfter`` option is passed to the ``watch()`` method
397
+ with a value of the ``_id`` of the last document processed, in order to recreate the
398
+ stream after it has been destroyed. Passing the ``_id`` to the change stream attempts
399
+ to resume notifications starting at the operation specified.
400
+
401
+ .. class:: copyable-code
402
+
403
+ .. literalinclude:: /driver-examples/change_stream_examples_spec.rb
404
+ :language: ruby
405
+ :dedent: 4
406
+ :start-after: Start Changestream Example 3
407
+ :end-before: End Changestream Example 3
339
408
340
409
341
410
As long as that operation has not rolled off the :term:`oplog`, the
0 commit comments