Effectively this is an upsert, we want to insert if the ${uniqueFieldToUpdateOn} is not in mongo, or update if it exists as follows.
There are two main ways of modelling data changes in a collection depending on your usecase update/replace as outlined below:
UPDATE
The following config states:
- Update ${uniqueFieldToUpdateOn} with a field that is unique to that record that you want to model your update on.
- AllowList (whitelist) this field For use with the
PartialValueStrategy
allows custom value fields to be projected for the id strategy.
- UpdateOneBusinessKeyTimestampStrategy means that only the one document referenced by the unique field declared above will be updated (Latest timestamp wins).
"document.id.strategy":"com.mongodb.kafka.connect.sink.processor.id.strategy.PartialValueStrategy",
"document.id.strategy.partial.value.projection.list":"${uniqueFieldToUpdateOn}",
"document.id.strategy.partial.value.projection.type":"AllowList",
"writemodel.strategy":"com.mongodb.kafka.connect.sink.writemodel.strategy.UpdateOneBusinessKeyTimestampStrategy"
REPLACE
NB this models a REPLACE not an update but may be useful none the less
The following config states:
- Replace ${uniqueFieldToUpdateOn} with a field that is unique to that record that you want to model your replace on.
- AllowList (whitelist) this field For use with the
PartialValueStrategy
allows custom value fields to be projected for the id strategy.
- ReplaceOneBusinessKeyStrategy means that only the one document referenced by the unique field declared above will be replaced.
"document.id.strategy":"com.mongodb.kafka.connect.sink.processor.id.strategy.PartialValueStrategy",
"document.id.strategy.partial.value.projection.list":"${uniqueFieldToUpdateOn}",
"document.id.strategy.partial.value.projection.type":"AllowList",
"writemodel.strategy":"com.mongodb.kafka.connect.sink.writemodel.strategy.ReplaceOneBusinessKeyStrategy"