Summary
The `Filters` coming with `mongodb-driver-kotlin-extensions` work in conjunction with `kotlinx-serialization`'s `@SerialName` annotation for regular data classes. They don't work for enum classes though.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
org.mongodb:mongodb-driver-kotlin-extensions:5.5.1
How to Reproduce
package demo import com.mongodb.kotlin.client.coroutine.MongoClient import com.mongodb.kotlin.client.model.Filters.eq import kotlinx.coroutines.runBlocking import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class Present(val color: PresentColor, val content: String?) @Serializable enum class PresentColor { @SerialName("blue") Blue, @SerialName("red") Red, @SerialName("yellow") Yellow, } fun main(): Unit = runBlocking { val database = MongoClient.create().getDatabase("test") val collection = database.getCollection<Present>("presents") collection.drop() collection.insertOne(Present(color = PresentColor.Red, content = "toys")) collection.insertOne(Present(color = PresentColor.Yellow, content = null)) collection.insertOne(Present(color = PresentColor.Blue, content = "chocolate")) collection.find(Present::content eq "toys").collect { println(it) } // ✅ prints Present(color=Red, content=toys) collection.find(Present::color eq PresentColor.Red).collect { println(it) } // ❌ does not print anything }
Additional Background