Skip to content

Switch to Standard UUID representation #5034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.x-GH-3932-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.x-GH-3932-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.x-GH-3932-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected boolean autoIndexCreation() {
protected MongoClientSettings mongoClientSettings() {

MongoClientSettings.Builder builder = MongoClientSettings.builder();
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
builder.uuidRepresentation(UuidRepresentation.STANDARD);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GH Issue says

Turn defaulting off and enforce an explicit choice from the user.

To do that, shouldn't this be changed to UuidRepresentation.UNSPECIFIED?

The risk of changing from JAVA_LEGACY to STANDARD is that applications with existing data can end up with a mix of UUID representations for the same field in the same collection, and then have a very difficult time querying their data.

Copy link
Member

@mp911de mp911de Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #5037 to track the further progress. Removing defaulting and failing early (instead of a delayed failure during save/query) would be an ideal signal to require additional configuration from the application. Removing defaults is going to create quite some inconvenience during upgrade.

Another alternative could be leaving defaults as-is but issuing warn logging if the default value is implicitly (i.e. not explicitly configured) used.

Also, I updated the original ticket description.

configureClientSettings(builder);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected MongoClientSettings computeClientSetting() {
getOrDefault(port, "" + ServerAddress.defaultPort())));

Builder builder = MongoClientSettings.builder().applyConnectionString(connectionString);
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
builder.uuidRepresentation(UuidRepresentation.STANDARD);

if (mongoClientSettings != null) {

Expand Down Expand Up @@ -291,7 +291,7 @@ protected MongoClientSettings computeClientSetting() {
applySettings(builder::retryWrites, computeSettingsValue(defaultSettings.getRetryWrites(),
mongoClientSettings.getRetryWrites(), connectionString.getRetryWritesValue()));
applySettings(builder::uuidRepresentation,
computeSettingsValue(null, mongoClientSettings.getUuidRepresentation(), UuidRepresentation.JAVA_LEGACY));
computeSettingsValue(null, mongoClientSettings.getUuidRepresentation(), UuidRepresentation.STANDARD));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use here constants and not connectionString.getUuidRepresentation()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess we're missing a test here - let's align with the above and add the test for it

}

if (!CollectionUtils.isEmpty(credential)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class MongoTestUtils {
private static final Environment ENV = new StandardEnvironment();
private static final Duration DEFAULT_TIMEOUT = Duration.ofMillis(10);

public static final String CONNECTION_STRING = "mongodb://127.0.0.1:27017/?replicaSet=rs0&w=majority&uuidrepresentation=javaLegacy";
public static final String CONNECTION_STRING = "mongodb://127.0.0.1:27017/?replicaSet=rs0&w=majority&uuidrepresentation=standard";

private static final String CONNECTION_STRING_PATTERN = "mongodb://%s:%s/?w=majority&uuidrepresentation=javaLegacy";
private static final String CONNECTION_STRING_PATTERN = "mongodb://%s:%s/?w=majority&uuidrepresentation=standard";

private static final Version ANY = new Version(9999, 9999, 9999);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ See xref:mongodb/mapping/custom-conversions.adoc[Custom Conversions - Overriding
| native
| `{"bin" : { "$binary" : "AQIDBA==", "$type" : "00" }}`

| `java.util.UUID` (Legacy UUID)
| `java.util.UUID` (Standard UUID)
| native
| `{"uuid" : { "$binary" : "MEaf1CFQ6lSphaa3b9AtlA==", "$type" : "03" }}`
| `{"uuid" : { "$binary" : "MEaf1CFQ6lSphaa3b9AtlA==", "$type" : "04" }}`

| `Date`
| native
Expand Down