Hello,
I’m trying to migrate from KMongo to the Kotlin driver, but I encountered an error with the codec: ‘Codec for id must implement RepresentationConfigurable to support BsonRepresentation’.
This is my MongoClient Service :
class MongoClientService {
val logger: Logger = LoggerFactory.getLogger(MongoClientService::class.java)
val mongoClient: MongoClient
init {
val codec = fromRegistries(
MongoClientSettings.getDefaultCodecRegistry(),
fromProviders(PojoCodecProvider.builder().automatic(true).build())
)
val settings = MongoClientSettings.builder()
.applyConnectionString(ConnectionString(AppConfig.APPLICATION_MONGODB_URI!!))
.codecRegistry(codec)
.build()
mongoClient = create(settings)
}
}
and my model
data class User(
@BsonId
@BsonRepresentation(BsonType.OBJECT_ID)
val id: ObjectId = ObjectId(),
var email: String,
var firstName: String,
var lastName: String,
var password: String,
var archived: Boolean = false,
val tenants: List<Tenant> = listOf(),
var language: Language = Language.EN,
val currentTenant: Tenant? = null,
val avatar: Avatar? = null,
val darkMode: Boolean = false,
val mode: AppMode = AppMode.EMPLOYEE,
val superAdmin: Boolean = false,
val entity: EntityEmbedded = EntityEmbedded(),
)
Does anyone have an idea ?