versioned_collection.collection.tracking_collections.modified module

class versioned_collection.collection.tracking_collections.modified.ModifiedCollection(*args: Any, **kwargs: Any)[source]

Bases: _BaseTrackerCollection

Stores references to the documents that were modified and untracked.

A temporary collection created upon the initialisation for tracking of a target collection. The documents in this collection store references to the documents that have been modified with respect to the latest registered version and the operation that modified the document. When a new version of the target collection is registered all the documents of this collection are removed.

A tracking document is added to this collection each time a document in the target collection is modified. This allows correctly registering versions of the target collection when large volumes of unacknowledged writes are performed.

The set of all tracking documents in this collection forms a total order, induced by the ordering property of ObjectIds. The documents that track the changes of a target document are ordered by the order of occurrence of the events that modified the target document, which can be restored by comparing the tracking document ids, i.e., the _id field.

class SCHEMA(_id: 'ObjectId', id: 'ObjectId', op: 'str')[source]

Bases: object

id: bson.ObjectId
op: str
delete_modified(ids: List[bson.ObjectId]) None[source]

Delete the tracked documents from this collection.

Note

This deletes only one of the trackers documents. A document from the tracked collection that has been modified multiple times has multiple trackers in this collection.

Parameters:

ids – The ids of the tracker documents.

get_modified_document_ids_by_operation() Dict[Literal['i', 'd', 'u'], List[bson.ObjectId]][source]

Return the document ids grouped by the operation type.

Returns:

The list of ids of the modified documents grouped by the type of the modifying operation. The valid types are 'i' for inserts, 'd' for deletes and 'u' for updates and replacements.

get_modified_trackers() List[ModifiedTracker][source]

Get the modified document ids and the ids of the trackers.

Returns:

A list of documents containing the ids of the modified documents in the tracked collection and the ids of the trackers in this collection, grouped by the modified document ids.

get_unique_modified_document_ids() List[bson.ObjectId][source]

Get the unique ids of the modified documents.

has_changes() bool[source]
class versioned_collection.collection.tracking_collections.modified.ModifiedTracker[source]

Bases: TypedDict

Representation for a modified document and its list of trackers.

tracker_ids: List[bson.ObjectId]