From 79e2e105c84dd7c8b5e45b3440fcb65d58a7e8e8 Mon Sep 17 00:00:00 2001 From: Szymon Marcinkiewicz Date: Wed, 6 Mar 2024 15:22:49 +0100 Subject: [PATCH 1/2] Use full documentKey from change event as query filter --- .../core/synchronization/ChangeEvent.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt b/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt index 3dab2ae..c92cf27 100644 --- a/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt +++ b/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt @@ -42,7 +42,6 @@ internal sealed class ChangeEvent( null } - protected fun idFilter() = Filters.eq("_id", documentKey.getValue("_id")) protected abstract fun toWriteModelImpl(): WriteModel companion object { @@ -89,7 +88,7 @@ internal data class InsertReplaceChangeEvent( } override fun toWriteModelImpl(): WriteModel = ReplaceOneModel( - idFilter(), + documentKey, document!!, ReplaceOptions().upsert(true) ) @@ -107,7 +106,7 @@ internal data class DeleteChangeEvent( ) } - override fun toWriteModelImpl(): WriteModel = DeleteOneModel(idFilter()) + override fun toWriteModelImpl(): WriteModel = DeleteOneModel(documentKey) } internal data class UpdateChangeEvent( @@ -132,7 +131,7 @@ internal data class UpdateChangeEvent( } override fun toWriteModelImpl(): WriteModel = UpdateOneModel( - idFilter(), + documentKey, Updates.combine( *updatedFields.entries.map { Updates.set(it.key, it.value) }.toTypedArray(), *removedFields.map { Updates.unset(it) }.toTypedArray() From 0e73be0d8718caaf2bc6f14fa7ca66095d12535a Mon Sep 17 00:00:00 2001 From: Szymon Marcinkiewicz Date: Wed, 6 Mar 2024 15:30:39 +0100 Subject: [PATCH 2/2] Remove unused import --- .../mongomigrationstream/core/synchronization/ChangeEvent.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt b/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt index c92cf27..f07b300 100644 --- a/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt +++ b/mongo-migration-stream-core/src/main/kotlin/pl/allegro/tech/mongomigrationstream/core/synchronization/ChangeEvent.kt @@ -2,7 +2,6 @@ package pl.allegro.tech.mongomigrationstream.core.synchronization import com.mongodb.DBRefCodecProvider import com.mongodb.client.model.DeleteOneModel -import com.mongodb.client.model.Filters import com.mongodb.client.model.ReplaceOneModel import com.mongodb.client.model.ReplaceOptions import com.mongodb.client.model.UpdateOneModel