@@ -2215,22 +2215,23 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
2215
2215
session = None ):
2216
2216
"""Watch changes on this collection.
2217
2217
2218
- Performs an aggregation with an implicit initial
2219
- `$changeStream aggregation stage`_ and returns a
2220
- :class:`~pymongo.change_stream.ChangeStream` cursor that iterates over
2221
- changes on this collection. Introduced in MongoDB 3.6.
2218
+ Performs an aggregation with an implicit initial ``$changeStream``
2219
+ stage and returns a :class:`~pymongo.change_stream.ChangeStream`
2220
+ cursor which iterates over changes on this collection.
2221
+ Introduced in MongoDB 3.6.
2222
2222
2223
2223
.. code-block:: python
2224
2224
2225
2225
for change in db.collection.watch():
2226
2226
print(change)
2227
2227
2228
- The ChangeStream returned automatically resumes when it
2229
- encounters a potentially recoverable error during iteration. The resume
2230
- process is transparent to the application and ensures no change stream
2231
- documents are lost; the call to
2232
- :meth:`~pymongo.change_stream.ChangeStream.next` blocks until the next
2233
- change document is returned or an unrecoverable error is raised.
2228
+ The :class:`~pymongo.change_stream.ChangeStream` iterable blocks
2229
+ until the next change document is returned or an error is raised. If
2230
+ the :meth:`~pymongo.change_stream.ChangeStream.next` method encounters
2231
+ a network error when retrieving a batch from the server, it will
2232
+ automatically attempt to recreate the cursor such that no change
2233
+ events are missed. Any error encountered during the resume attempt
2234
+ indicates there may be an outage and will be raised.
2234
2235
2235
2236
.. code-block:: python
2236
2237
@@ -2239,29 +2240,29 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
2239
2240
[{'$match': {'operationType': 'insert'}}]):
2240
2241
print(insert_change)
2241
2242
except pymongo.errors.PyMongoError:
2242
- # We know for sure it's unrecoverable:
2243
+ # The ChangeStream encountered an unrecoverable error or the
2244
+ # resume attempt failed to recreate the cursor.
2243
2245
log.error('...')
2244
2246
2245
2247
For a precise description of the resume process see the
2246
- `Change Streams specification`_.
2248
+ `change streams specification`_.
2247
2249
2248
2250
.. note:: Using this helper method is preferred to directly calling
2249
2251
:meth:`~pymongo.collection.Collection.aggregate` with a
2250
- ``$changeStream`` aggregation stage, for the purpose of supporting
2252
+ ``$changeStream`` stage, for the purpose of supporting
2251
2253
resumability.
2252
2254
2253
2255
.. warning:: This Collection's :attr:`read_concern` must be
2254
2256
``ReadConcern("majority")`` in order to use the ``$changeStream``
2255
- aggregation stage.
2257
+ stage.
2256
2258
2257
2259
:Parameters:
2258
2260
- `pipeline` (optional): A list of aggregation pipeline stages to
2259
- append to an initial `$changeStream` aggregation stage. Not all
2260
- pipeline stages are valid after a `$changeStream` stage, see the
2261
- `$changeStream aggregation stage`_ documentation for the supported
2262
- stages.
2261
+ append to an initial ``$changeStream`` stage. Not all
2262
+ pipeline stages are valid after a ``$changeStream`` stage, see the
2263
+ MongoDB documentation on change streams for the supported stages.
2263
2264
- `full_document` (optional): The fullDocument to pass as an option
2264
- to the $changeStream pipeline stage. Allowed values: 'default',
2265
+ to the `` $changeStream`` stage. Allowed values: 'default',
2265
2266
'updateLookup'. Defaults to 'default'.
2266
2267
When set to 'updateLookup', the change notification for partial
2267
2268
updates will include both a delta describing the changes to the
@@ -2284,10 +2285,9 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
2284
2285
2285
2286
.. versionadded:: 3.6
2286
2287
2287
- .. _$changeStream aggregation stage:
2288
- https://docs.mongodb.com/manual/reference/operator/aggregation/changeStream/
2288
+ .. mongodoc:: changeStreams
2289
2289
2290
- .. _Change Streams specification:
2290
+ .. _change streams specification:
2291
2291
https://github.com/mongodb/specifications/blob/master/source/change-streams.rst
2292
2292
"""
2293
2293
if pipeline is None :
0 commit comments