Skip to content

Commit

Permalink
Fix MongoDB primary key (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Dec 20, 2024
1 parent 09aa180 commit ef85a7a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 2 additions & 1 deletion integration_tests/mongo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func testTypes(ctx context.Context, db *mongo.Database, mongoCfg config.MongoDB)
}

row := rows[0]
expectedPartitionKey := map[string]any{"payload": map[string]any{"id": `{"$oid":"66a95fae3776c2f21f0ff568"}`}}
// This should not include the payload field in here. The payload field gets injected in [kafkalib.buildKafkaMessageWrapper]
expectedPartitionKey := map[string]any{"id": `{"$oid":"66a95fae3776c2f21f0ff568"}`}
expectedPkBytes, err := json.Marshal(expectedPartitionKey)
if err != nil {
return fmt.Errorf("failed to marshal expected partition key: %w", err)
Expand Down
7 changes: 1 addition & 6 deletions lib/mongo/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ func (m *Message) ToRawMessage(collection config.Collection, database string) (l
Operation: m.operation,
},
}

pkMap := map[string]any{
"payload": m.pkMap,
}

// MongoDB wouldn't include the schema.
return lib.NewRawMessage(collection.TopicSuffix(database), debezium.FieldsObject{}, pkMap, evt), nil
return lib.NewRawMessage(collection.TopicSuffix(database), debezium.FieldsObject{}, m.pkMap, evt), nil
}

func ParseMessage(after bson.M, before *bson.M, op string) (*Message, error) {
Expand Down

0 comments on commit ef85a7a

Please sign in to comment.