versioned_collection.listener module

class versioned_collection.listener.CollectionListener(database_name: str, collection_name: str, host: str = 'localhost', port: int = 27017, credentials: Tuple[str | None, str | None] | None = None)[source]

Bases: object

Listens to changes to a specific collection.

Starts a background process that monitors the target collection for any changes and stores the ids of the updated documents in the ModifiedCollection linked to the target collection.

is_listening() bool[source]

Check if this listener has started listening to changes.

Returns:

Whether the listener is listening or not.

start() None[source]

Start the listener to monitor the target collection.

Lunches a monitoring daemon that uses changeStreams to watch the target collection for all types of updates.

Blocks until the listener daemon has successfully started to prevent the client from modifying the target collection.

stop() None[source]

Stop this listener from monitoring the target collection.

The listener is safely stopped to allow the changes (that were produced before signaling the listener to stop) to be processed. This is relevant when a large number of entries are modified in any way from the tracked collection in a transaction, or when unacknowledged operations are performed and the database queues the operations to be performed.