Kotlin Synchronized Driver: Mocking updateOne

Hello,
I am currently working with the synchronized MongoDB driver and Kotlin. Thereby I find it quite difficult to mock different methods like findOneAndUpdate. But that would be important for my tests. For mocking I use MockK. Example:

private lateinit var db: MongoDatabase
private lateinit var collection: MongoCollection<MyObject>
private lateinit var service: MyService

@BeforeEach
fun setUp() {
  db = mockk()
  collection = mockk()
  service = MyService(db)
}

@Test
fun example() {
  val expectedObject = MyObject()
  every { db.getCollection("myCollection").withDocumentClass<MyObject>() } returns collection
  every { collection.findOneAndUpdate(any<Document>(), any<Document>()) } returns expectedObject

  val obj = service.doSmth("Test")

  assertThat(obj).isEqualTo(expectedObject)
}

The code will not run successfully this way, because for the method call findOneAndUpdate of the mocked collection, no answer can be found. In the code that is tested, the following is called:

class MyService(db: MongoDatabase) {
  fun doSmth(newValue: String): MyObject {
    val collection = db.getCollection("myCollection").withDocumentClass<MyObject>()
    return collection.findOneAndUpdate(Document(mapOf("_id", "test")), Document(mapOf("test", newValue)))
  } 
}

This test does work with the find method.
Actually it should work like this, but probably I am not paying attention to something important. Can someone help me with this?

Many greetings,
Finn

Here are some more detailed examples and a specific error message.

build.gradle.kts

val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project

val prometeus_version: String by project
plugins {
    kotlin("jvm") version "1.9.10"
    id("io.ktor.plugin") version "2.3.4"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
}

group = "com.example"
version = "0.0.1"

application {
    mainClass.set("com.example.ApplicationKt")

    val isDevelopment: Boolean = project.ext.has("development")
    applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.ktor:ktor-server-core-jvm")
    implementation("io.ktor:ktor-server-cors-jvm")
    implementation("io.ktor:ktor-server-metrics-micrometer-jvm")
    implementation("io.micrometer:micrometer-registry-prometheus:$prometeus_version")
    implementation("io.ktor:ktor-server-content-negotiation-jvm")
    implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
    implementation("io.ktor:ktor-server-netty-jvm")
    implementation("ch.qos.logback:logback-classic:$logback_version")
    implementation("org.mongodb:mongodb-driver-kotlin-sync:4.10.2")

    testImplementation("io.ktor:ktor-server-tests-jvm")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
    testImplementation("io.mockk:mockk:1.13.7")
    testImplementation("org.assertj:assertj-core:3.24.2")
}

MyService

package com.example.services

import com.example.models.MyClass
import com.mongodb.client.model.Filters.eq
import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.MongoDatabase

class MyService(private val db: MongoDatabase) {
    fun doSmth(value: String): MyClass? {
        val collection = db.getCollection<MyClass>("myCollection").withDocumentClass<MyClass>()

        return collection.findOneAndUpdate(eq(MyClass::id.name, "myConstantKeyValue"), Updates.set("myField", value))
    }
}

MyClass

package com.example.models

import org.bson.codecs.pojo.annotations.BsonId

data class MyClass(@BsonId val id: String, val myField: String)

MyServiceTest

package com.example.services

import com.example.models.MyClass
import com.mongodb.kotlin.client.MongoCollection
import com.mongodb.kotlin.client.MongoDatabase
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
import org.bson.Document
import org.junit.Before
import org.junit.Test

class MyServiceTest {
    private lateinit var db: MongoDatabase
    private lateinit var collection: MongoCollection<MyClass>
    private lateinit var myService: MyService

    @Before
    fun setUp() {
        db = mockk()
        collection = mockk()
        myService = MyService(db)
    }

    @Test
    fun `should find and update MyClass object`() {
        val expectedMyClass = MyClass("myId", "myNewValue")
        every { db.getCollection<MyClass>("myCollection").withDocumentClass<MyClass>() } returns collection
        every { collection.findOneAndUpdate(any<Document>(), any<Document>()) } returns expectedMyClass

        val myClass = myService.doSmth("myNewValue")

        assertThat(myClass).isEqualTo(expectedMyClass)
    }
}

Error Message

io.mockk.MockKException: no answer found for MongoCollection(#2).findOneAndUpdate(Filter{fieldName='id', value=myConstantKeyValue}, Update{fieldName='myField', operator='$set', value=myNewValue}, FindOneAndUpdateOptions{projection=null, sort=null, upsert=false, returnDocument=BEFORE, maxTimeMS=0, bypassDocumentValidation=null, collation=null, arrayFilters=null, hint=null, hintString=null, comment=null, let=null}) among the configured answers: (MongoCollection(#2).findOneAndUpdate(any(), any(), eq(FindOneAndUpdateOptions{projection=null, sort=null, upsert=false, returnDocument=BEFORE, maxTimeMS=0, bypassDocumentValidation=null, collation=null, arrayFilters=null, hint=null, hintString=null, comment=null, let=null}))))