Skip to content

Commit 9d7b4c4

Browse files
committed
PYTHON-1338 Update change stream documentation.
1 parent a689aa6 commit 9d7b4c4

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

pymongo/change_stream.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,8 @@ class ChangeStream(object):
2626
Should not be called directly by application developers. Use
2727
:meth:`~pymongo.collection.Collection.watch` instead.
2828
29-
:Parameters:
30-
- `collection`: The watched :class:`~pymongo.collection.Collection`.
31-
- `pipeline`: A list of aggregation pipeline stages to append to an
32-
initial `$changeStream` aggregation stage.
33-
- `full_document` (string): The fullDocument to pass as an option
34-
to the $changeStream pipeline stage. Allowed values: 'default',
35-
'updateLookup'. When set to 'updateLookup', the change notification
36-
for partial updates will include both a delta describing the
37-
changes to the document, as well as a copy of the entire document
38-
that was changed from some time after the change occurred.
39-
- `resume_after` (optional): The logical starting point for this
40-
change stream.
41-
- `max_await_time_ms` (optional): The maximum time in milliseconds
42-
for the server to wait for changes before responding to a getMore
43-
operation.
44-
- `batch_size` (optional): The maximum number of documents to return
45-
per batch.
46-
- `collation` (optional): The :class:`~pymongo.collation.Collation`
47-
to use for the aggregation.
48-
- `session` (optional): a
49-
:class:`~pymongo.client_session.ClientSession`.
50-
5129
.. versionadded: 3.6
30+
.. mongodoc:: changeStreams
5231
"""
5332
def __init__(self, collection, pipeline, full_document,
5433
resume_after=None, max_await_time_ms=None, batch_size=None,

pymongo/collection.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)