import org.litote.kmongo.KMongo
fun main() {
val client = Kmongo.createClient(/* connection string from mongodb */)
val database = client.getDatabase(/* databaseName */)
}
my code ^
this is what it returns:
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Changing the default UuidRepresentation requires a CodecRegistry that also implements the CodecProvider interface
at org.litote.kmongo.KMongo.createRegistry(KMongo.kt:89)
at org.litote.kmongo.KMongo.createClient(KMongo.kt:78)
at org.litote.kmongo.KMongo.createClient(KMongo.kt:60)
at org.litote.kmongo.KMongo.createClient(KMongo.kt:50)
at MainKt.main(Main.kt:3)
at MainKt.main(Main.kt)
for security purposes, i have omitted the additional code that are irrelevant and the database names
Thanks for your help in advance!
From
kmongo
source here: https://github.com/Litote/kmongo/blob/master/kmongo-core/src/main/kotlin/org/litote/kmongo/KMongo.kt, it seems that this is happening because the UUID Representation isJAVA_LEGACY
.Hence, you should supply a
MongoClientSettings
object tocreateClient
, which specifies a UUID representation other thanJAVA_LEGACY
. Since UuidRepresentation is an enum (https://mongodb.github.io/mongo-java-driver/3.5/javadoc/org/bson/UuidRepresentation.html), you can try usingSTANDARD
.Like this:
This should get KMongo/MongoDB to use
UuidRepresentation.STANDARD
instead ofUuidRepresentation.JAVA_LEGACY
(in which KMongo will always throw an exception)Thanks!