Is there a way to dynamically choose the WriteStrategy of a MongoDB sink connector?
Use case at hand -
Read from a topic and write to mongo atlas using mongodb sink connector in a way that the ordering of these writes is kept intact in the way that the events occured on a given partition of the source topic. The source topic will be partitioned on the business key that is then used to do one of the below 3 on atlas -
- Insert new Document (possibly use InsertOneDefaultStrategy)
- Update an existing document based on business key (possibly use UpdateOneBusinessKeyTimestampStrategy)
- Delete an existing document based on business key (possibly use DeleteOneBusinessKeyStrategy)
I am also thinking if I could use ReplaceOneBusinessKeyStrategy to keep things easier - but it doesnt satisfy the delete requirement - for which I am contemplating if I should do some sort of soft deletes.
Writing a custom write strategy is another option - but not sure if I want to invest time and effort in coming up with something custom.
I cannot have multiple source topics for each event type for ordering concerns.
It would have been nice if I could choose Write strategies dynamically based on some header or metadata field in the input message.
Any suggestions or feedback are welcome.
I feel like you'll have to invest some time to write a custom write strategy. There is the
topic.override.<topic>.<property>
setting where you can specify different settings for different topics, ie writemodel strategy.I guess the easiest way is to include a document field that describes an action that you want to perform, and apply the relevant action to the document.