diff --git a/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt b/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt index e8b9a946..7111fd2f 100644 --- a/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt +++ b/driver-multiplatform/src/commonMain/kotlin/MultiplatformMongoCollectionImpl.kt @@ -412,15 +412,84 @@ internal class MultiplatformMongoCollectionImpl( } override suspend fun updateManyWithPipeline(options: UpdateOptions.() -> Unit, filter: FilterQuery.() -> Unit, update: UpdateWithPipelineQuery.() -> Unit): UpdateOperations.UpdateResult { - TODO("Not yet implemented") + val model = UpdateManyWithPipeline( + context = database.client.context, + ).apply { + this.options.options() + this.filter.filter() + this.update.update() + } + + val message = database.client.wire.sendSingle( + database.client.createOpMsg { + document { + writeString("update", name) + writeString($$"$db", database.name) + model.writeTo(this) + } + } + ) + + message as Message.OpMsg + check(message.body.document["ok"]?.decodeDouble() == 1.0) + + // TODO handle unacknowledged updates + + return MultiplatformAcknowledgedUpdateResult(message.body.document) } override suspend fun updateOneWithPipeline(options: UpdateOptions.() -> Unit, filter: FilterQuery.() -> Unit, update: UpdateWithPipelineQuery.() -> Unit): UpdateOperations.UpdateResult { - TODO("Not yet implemented") + val model = UpdateOneWithPipeline( + context = database.client.context, + ).apply { + this.options.options() + this.filter.filter() + this.update.update() + } + + val message = database.client.wire.sendSingle( + database.client.createOpMsg { + document { + writeString("update", name) + writeString($$"$db", database.name) + model.writeTo(this) + } + } + ) + + message as Message.OpMsg + check(message.body.document["ok"]?.decodeDouble() == 1.0) + + // TODO handle unacknowledged updates + + return MultiplatformAcknowledgedUpdateResult(message.body.document) } override suspend fun upsertOneWithPipeline(options: UpdateOptions.() -> Unit, filter: FilterQuery.() -> Unit, update: UpdateWithPipelineQuery.() -> Unit): MultiplatformMongoCollection.UpsertResult { - TODO("Not yet implemented") + val model = UpsertOneWithPipeline( + context = database.client.context, + ).apply { + this.options.options() + this.filter.filter() + this.update.update() + } + + val message = database.client.wire.sendSingle( + database.client.createOpMsg { + document { + writeString("update", name) + writeString($$"$db", database.name) + model.writeTo(this) + } + } + ) + + message as Message.OpMsg + check(message.body.document["ok"]?.decodeDouble() == 1.0) + + // TODO handle unacknowledged updates + + return MultiplatformAcknowledgedUpdateResult(message.body.document) } override fun toString(): String =