Categorygithub.com/mmtracker/mongowatch
modulepackage
0.0.0-20231128160947-0b358fea5cd0
Repository: https://github.com/mmtracker/mongowatch.git
Documentation: pkg.go.dev

# README

mongowatch

MongoDB Event Stream Watcher

Watches target mongo collection using mongo event log and executes certain handlers based on subscribed collection changes.

Self healing

If the collection was renamed, dropped or recreated, the event stream produces an 'invalidate' event for which the watcher is implemented to recover automatically from.

However make sure to reapply the collMod command options to the collection (if necessary).

This package contains helper methods to do it (make sure you have the right Mongo user permissions):

For Mongo >= 6.0

collMod changeStreamPreAndPostImages

db.EnablePrePostImages(mongoInstance *mongo.Database, colName string) error

For Mongo < 6.0

collMod recordPreImages

db.RecordPreImages(mongoInstance *mongo.Database, colName string) error

Package testing

To be able to run tests in this repo you will need to have some local and remote mongo instances running on port 27017. Configure parts with TODO comments.

Courtesy of @ignasbernotas and @zolia

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author

# Structs

ChangeStreamEvent is the customized representation of a MongoDB change stream event that is captured and processed by this application.
ChangeStreamResumePoint holds information needed to resume a change stream from a specific point.
ResumeToken denotes the token associated with a MongoDB change stream event, which may be used to resume receiving change stream events from a point in the past.

# Interfaces

ChangeStreamWatcher watches a change stream and dispatches received changed events.
CollectionWatcher is an interface for processing document data from a change stream.
DocumentProcessor is an interface for processing document data from a change stream.
StreamResume stores relevant change stream events mongo's oplog has configurable expiration, but we don't need a large oplog instead we store the changes we actually need.

# Type aliases

ChangeEventDispatcherFunc change event callback function returning err will stop further ChangeEventDispatcherFunc processing and the change stream watcher.