Skip to content

Commit

Permalink
Supporting DocDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Aug 17, 2024
1 parent 9898166 commit 43edffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type MongoDB struct {
Collections []Collection `yaml:"collections"`
StreamingSettings StreamingSettings `yaml:"streamingSettings,omitempty"`
DisableTLS bool `yaml:"disableTLS,omitempty"`

// DisableFullDocumentBeforeChange - This is relevant if you're connecting to Document DB.
// BSON field '$changeStream.fullDocumentBeforeChange' is an unknown field.
DisableFullDocumentBeforeChange bool `yaml:"disableFullDocumentBeforeChange,omitempty"`
}

type Collection struct {
Expand Down
10 changes: 7 additions & 3 deletions sources/mongo/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ func newStreamingIterator(ctx context.Context, db *mongo.Database, cfg config.Mo
opts := options.ChangeStream().
// Setting `updateLookup` will emit the whole document for updates
// Ref: https://www.mongodb.com/docs/manual/reference/change-events/update/#description
SetFullDocument(options.UpdateLookup).
// FullDocumentBeforeChange will kick in if the db + collection enabled `changeStreamPreAndPostImages`
SetFullDocumentBeforeChange(options.WhenAvailable)
SetFullDocument(options.UpdateLookup)

if !cfg.DisableFullDocumentBeforeChange {
opts = opts.
// FullDocumentBeforeChange will kick in if the db + collection enabled `changeStreamPreAndPostImages`
SetFullDocumentBeforeChange(options.WhenAvailable)
}

storage := persistedmap.NewPersistedMap(filePath)
if encodedResumeToken, exists := storage.Get(offsetKey); exists {
Expand Down

0 comments on commit 43edffa

Please sign in to comment.