MonsterChenzhuo commented on code in PR #4833:
URL: https://github.com/apache/seatunnel/pull/4833#discussion_r1207598335


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/RowDataDocumentSerializer.java:
##########
@@ -52,6 +56,20 @@ public RowDataDocumentSerializer(
 
     @Override
     public WriteModel<BsonDocument> serializeToWriteModel(SeaTunnelRow row) {
+        switch (row.getRowKind()) {
+            case INSERT:
+            case UPDATE_AFTER:
+                return upsert(row);
+            case UPDATE_BEFORE:

Review Comment:
   [强]
   When upsert (a combination of insert and update) operation is enabled, the 
UPDATE_BEFORE type of operation is usually ignored. This is because in an 
upsert operation, if there is no matching row in the database for the update 
operation, an insert operation is performed. If a matching row exists, an 
update operation is performed. In this scenario, the UPDATE_BEFORE type of 
operation becomes irrelevant as it is retracting the previous row before the 
update, but in an upsert operation, that row doesn't exist.
   
   Therefore, to avoid confusion and redundancy, it is reasonable to ignore the 
UPDATE_BEFORE type of operation when upsert operation is enabled. Only INSERT 
and UPDATE_AFTER types of operations, which represent the content of the 
inserted or updated rows, are considered to ensure the correct execution of the 
upsert operation. This simplifies the code logic and improves efficiency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to