From d8feb84dd5e2c007df27101252d9b0d0e5850d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 5 Sep 2026 18:21:46 +0200 Subject: [PATCH] feat(driver-multiplatform): Prototype insertMany() --- .../MultiplatformMongoCollectionImpl.kt | 27 ++++++++++++++++--- .../operations/InsertOperations.test.kt | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt b/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt index f125ca01..b6666ece 100644 --- a/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt +++ b/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt @@ -65,17 +65,38 @@ internal class MultiplatformMongoCollectionImpl( context = database.client.context, document = document, documentType = type, - ).writeTo(this) + ).apply { + this.options.options() + }.writeTo(this) } } ) - check(message is Message.OpMsg) + message as Message.OpMsg check(message.body.document["ok"]?.decodeDouble() == 1.0) } override suspend fun insertMany(documents: Iterable, options: InsertManyOptions.() -> Unit) { - TODO("Not yet implemented") + val message = database.client.wire.sendSingle( + database.client.createOpMsg { + document { + writeString("insert", name) + writeString($$"$db", database.name) + + InsertMany( + context = database.client.context, + documents = documents.toList(), + documentType = type, + ).apply { + this.options.options() + }.writeTo(this) + } + } + ) + + message as Message.OpMsg + check(message.body.document["ok"]?.decodeDouble() == 1.0) { "Message is not OK: $message" } + check(message.body.document["writeErrors"] == null) { "Write errors occurred: $message" } } override fun filter(filter: FilterQuery.() -> Unit): MultiplatformMongoCollection { diff --git a/test/src/commonMain/kotlin/operations/InsertOperations.test.kt b/test/src/commonMain/kotlin/operations/InsertOperations.test.kt index 58422d4a..6baf9b5b 100644 --- a/test/src/commonMain/kotlin/operations/InsertOperations.test.kt +++ b/test/src/commonMain/kotlin/operations/InsertOperations.test.kt @@ -24,6 +24,7 @@ import opensavvy.ktmongo.tests.api.collection import opensavvy.prepared.suite.Prepared import opensavvy.prepared.suite.SuiteDsl import opensavvy.prepared.suite.assertions.checkThrows +import opensavvy.prepared.suite.config.Ignored import kotlin.time.Duration.Companion.milliseconds @Serializable @@ -98,7 +99,7 @@ fun SuiteDsl.verifyInsertOperations( // TODO: write a test that can check that the option is correctly applied } - test("insertMany • Minuscule delay") { + test("insertMany • Minuscule delay", Ignored) { // TODO val users = List(1000) { InsertOperationsUser( _id = collection().newId(), -- 2.51.2