[KAFKA-255] Add UpdateOneDefaultStrategy Created: 21/Oct/21  Updated: 28/Oct/23  Resolved: 11/Aug/23

Status: Closed
Project: Kafka Connector
Component/s: Sink
Affects Version/s: None
Fix Version/s: 1.11.0

Type: Improvement Priority: Minor - P4
Reporter: Robert Walters Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Quarter: FY23Q4
Documentation Changes: Needed

 Description   

Currently the default write model strategy is replace, there has been requests for performing an update.  

 
replace one (current default) is an upsert, however if the document exists it replaces the whole document with the new one. The problem can be seen if the existing document is:
{_id: 1, a: 0, b: 0, c:0}
and you replace with 
{_id: 1, a: 1}
the destination document will be 
}}{{{_id: 1, a: 1}{{}}
{{}}
not
{_id: 1, a: 1,b: 0, c:0}

We should add a UpdateOneDefaultStrategy such that the destination document in this scenario will be
{_id: 1, a: 1,b: 0, c:0}



 Comments   
Comment by Githook User [ 11/Aug/23 ]

Author:

{'name': 'Ross Lawley', 'email': 'ross@mongodb.com', 'username': 'rozza'}

Message: Added UpdateOneDefaultStrategy (#144)

A WriteStrategy that performs a `$set` upsert operation.
For scenarios where the topic data contains fragments of the
desired data in MongoDB

KAFKA-255
Branch: master
https://github.com/mongodb/mongo-kafka/commit/358ce92d1a490eebab74f6aeb18a6d7c5f23243b

Comment by Ross Lawley [ 09/Aug/23 ]

Add UpdateOneDefaultStrategy to the strategies list

Description:
Updates at most one document in MongoDB that matches a sink record by the _id field. If no documents match, insert the sink record as a new document. Will only update fields present in the sink record, so can be used in scenarios where the sink record only contains fragements of the store data in MongoDB.
Apply the following configuration to your sink connector to specify this setting:

writemodel.strategy=com.mongodb.kafka.connect.sink.writemodel.strategy.UpdateOneDefaultStrategy

Generated at Thu Feb 08 09:05:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.