Vous êtes un professionnel et vous avez besoin d'une formation ?
Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Classe « AsyncMongoClient »
Signature de la méthode watch
def watch(self, pipeline: 'Optional[_Pipeline]' = None, full_document: 'Optional[str]' = None, resume_after: 'Optional[Mapping[str, Any]]' = None, max_await_time_ms: 'Optional[int]' = None, batch_size: 'Optional[int]' = None, collation: 'Optional[_CollationIn]' = None, start_at_operation_time: 'Optional[Timestamp]' = None, session: 'Optional[client_session.AsyncClientSession]' = None, start_after: 'Optional[Mapping[str, Any]]' = None, comment: 'Optional[Any]' = None, full_document_before_change: 'Optional[str]' = None, show_expanded_events: 'Optional[bool]' = None) -> 'AsyncChangeStream[_DocumentType]'
Description
help(AsyncMongoClient.watch)
Watch changes on this cluster.
Performs an aggregation with an implicit initial ``$changeStream``
stage and returns a
:class:`~pymongo.asynchronous.change_stream.AsyncClusterChangeStream` cursor which
iterates over changes on all databases on this cluster.
Introduced in MongoDB 4.0.
.. code-block:: python
with client.watch() as stream:
for change in stream:
print(change)
The :class:`~pymongo.asynchronous.change_stream.AsyncClusterChangeStream` iterable
blocks until the next change document is returned or an error is
raised. If the
:meth:`~pymongo.asynchronous.change_stream.AsyncClusterChangeStream.next` method
encounters a network error when retrieving a batch from the server,
it will automatically attempt to recreate the cursor such that no
change events are missed. Any error encountered during the resume
attempt indicates there may be an outage and will be raised.
.. code-block:: python
try:
with client.watch([{"$match": {"operationType": "insert"}}]) as stream:
for insert_change in stream:
print(insert_change)
except pymongo.errors.PyMongoError:
# The AsyncChangeStream encountered an unrecoverable error or the
# resume attempt failed to recreate the cursor.
logging.error("...")
For a precise description of the resume process see the
`change streams specification`_.
:param pipeline: A list of aggregation pipeline stages to
append to an initial ``$changeStream`` stage. Not all
pipeline stages are valid after a ``$changeStream`` stage, see the
MongoDB documentation on change streams for the supported stages.
:param full_document: The fullDocument to pass as an option
to the ``$changeStream`` stage. Allowed values: 'updateLookup',
'whenAvailable', 'required'. When set to 'updateLookup', the
change notification for partial updates will include both a delta
describing the changes to the document, as well as a copy of the
entire document that was changed from some time after the change
occurred.
:param full_document_before_change: Allowed values: 'whenAvailable'
and 'required'. Change events may now result in a
'fullDocumentBeforeChange' response field.
:param resume_after: A resume token. If provided, the
change stream will start returning changes that occur directly
after the operation specified in the resume token. A resume token
is the _id value of a change document.
:param max_await_time_ms: The maximum time in milliseconds
for the server to wait for changes before responding to a getMore
operation.
:param batch_size: The maximum number of documents to return
per batch.
:param collation: The :class:`~pymongo.collation.Collation`
to use for the aggregation.
:param start_at_operation_time: If provided, the resulting
change stream will only return changes that occurred at or after
the specified :class:`~bson.timestamp.Timestamp`. Requires
MongoDB >= 4.0.
:param session: a
:class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
:param start_after: The same as `resume_after` except that
`start_after` can resume notifications after an invalidate event.
This option and `resume_after` are mutually exclusive.
:param comment: A user-provided comment to attach to this
command.
:param show_expanded_events: Include expanded events such as DDL events like `dropIndexes`.
:return: A :class:`~pymongo.asynchronous.change_stream.AsyncClusterChangeStream` cursor.
.. versionchanged:: 4.3
Added `show_expanded_events` parameter.
.. versionchanged:: 4.2
Added ``full_document_before_change`` parameter.
.. versionchanged:: 4.1
Added ``comment`` parameter.
.. versionchanged:: 3.9
Added the ``start_after`` parameter.
.. versionadded:: 3.7
.. seealso:: The MongoDB documentation on `changeStreams <https://mongodb.com/docs/manual/changeStreams/>`_.
.. _change streams specification:
https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.md
Vous êtes un professionnel et vous avez besoin d'une formation ?
Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :