kmongo
kmongo copied to clipboard
replaceOneById doesn't use a custom CodecRegistry
replaceOneById -> replaceOneWithoutId -> KMongoUtil.filterIdToBson -> SerializationClassMappingTypeService::filterIdToBson
I think in this line , it should access a custom codec registry that a user registered by MongoCollection::withCodecRegistry(registry)
. Because of this, it fails to find a codec and fails serialization.
Thank you for reporting. Could you provide a reproducible use case ? I infer it does not work for for a collection class that use a custom codec ? For which mapping engine ?
Thanks. Yes, when a collection with a custom codec registry calls .replaceOne()
(or any method depending on KMongoUtil.filterIdToBson()
), it ignores the registered codec registry; it uses a KMongo internal shared codec registry in SerializationClassMappingTypeService instead. Not sure about mapping engines, our project uses Kotlinx Serialization for serialization, but I don't think it affects the root cause.
Workaround: add the codec in MongoClientSettings.codecRegistry
in KMongo.createClient(MongoClientSettings)
. Needs a major refactoring to fix the bug because the KMongoUtil.filterIdToBson()
is stateless