@@ -2215,22 +2215,23 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
22152215 session = None ):
22162216 """Watch changes on this collection.
22172217
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.
22222222
22232223 .. code-block:: python
22242224
22252225 for change in db.collection.watch():
22262226 print(change)
22272227
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.
22342235
22352236 .. code-block:: python
22362237
@@ -2239,29 +2240,29 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
22392240 [{'$match': {'operationType': 'insert'}}]):
22402241 print(insert_change)
22412242 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.
22432245 log.error('...')
22442246
22452247 For a precise description of the resume process see the
2246- `Change Streams specification`_.
2248+ `change streams specification`_.
22472249
22482250 .. note:: Using this helper method is preferred to directly calling
22492251 :meth:`~pymongo.collection.Collection.aggregate` with a
2250- ``$changeStream`` aggregation stage, for the purpose of supporting
2252+ ``$changeStream`` stage, for the purpose of supporting
22512253 resumability.
22522254
22532255 .. warning:: This Collection's :attr:`read_concern` must be
22542256 ``ReadConcern("majority")`` in order to use the ``$changeStream``
2255- aggregation stage.
2257+ stage.
22562258
22572259 :Parameters:
22582260 - `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.
22632264 - `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',
22652266 'updateLookup'. Defaults to 'default'.
22662267 When set to 'updateLookup', the change notification for partial
22672268 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,
22842285
22852286 .. versionadded:: 3.6
22862287
2287- .. _$changeStream aggregation stage:
2288- https://docs.mongodb.com/manual/reference/operator/aggregation/changeStream/
2288+ .. mongodoc:: changeStreams
22892289
2290- .. _Change Streams specification:
2290+ .. _change streams specification:
22912291 https://github.com/mongodb/specifications/blob/master/source/change-streams.rst
22922292 """
22932293 if pipeline is None :
0 commit comments