I upgraded to Spring Boot 2.2.0.RELEASE and wanted to replace the now deprecated AbstractMongoConfiguration with AbstractMongoClientConfiguration. I am using
codecRegistries.add(CodecRegistries.fromCodecs(new UuidCodec(UuidRepresentation.STANDARD)));
to set the UUID Codec in the MongoDB to STANDARD (UUID) instead of Legacy Codec (LUUID). When looking into the database the Codec stays in the legacy format. Anybody else experienced the same problem?
Old implementation (working):
@Override
public MongoClient mongoClient() {
CodecRegistry codecRegistry =
CodecRegistries.fromRegistries(CodecRegistries.fromCodecs(new UuidCodec(UuidRepresentation.STANDARD)),
MongoClient.getDefaultCodecRegistry());
return new MongoClient(new ServerAddress(address, port), MongoClientOptions.builder().codecRegistry(codecRegistry).build());
}
New implementation (not working):
@Override
public MongoClient mongoClient() {
List<CodecRegistry> codecRegistries = new ArrayList<>();
codecRegistries.add(CodecRegistries.fromCodecs(new DocumentCodec()));
codecRegistries.add(CodecRegistries.fromCodecs(new UuidCodec(UuidRepresentation.STANDARD)));
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(codecRegistries);
return MongoClients.create(MongoClientSettings.builder()
.codecRegistry(codecRegistry)
.applyConnectionString(new ConnectionString(connectionString))
.build());
}
I expected the UUID Codec in the database to adjust to Standard Codec but it stays in Legacy Codec.