From 1ac6c481c8dd9cf788bf5ee767c684d5e0086df4 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 28 Oct 2025 12:51:52 +0100 Subject: [PATCH 1/2] Prepare issue branch. --- pom.xml | 2 +- spring-data-mongodb-distribution/pom.xml | 2 +- spring-data-mongodb/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b23a16229f..0d92fb4912 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 5.0.0-SNAPSHOT + 5.0.x-GH-5074-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index fc88571622..322163d910 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -15,7 +15,7 @@ org.springframework.data spring-data-mongodb-parent - 5.0.0-SNAPSHOT + 5.0.x-GH-5074-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 37730f7d40..4fb79e7392 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -13,7 +13,7 @@ org.springframework.data spring-data-mongodb-parent - 5.0.0-SNAPSHOT + 5.0.x-GH-5074-SNAPSHOT ../pom.xml From 53c888413854ae16e74e63b3c08fa6f20fc184a3 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 28 Oct 2025 13:15:12 +0100 Subject: [PATCH 2/2] Deprecate background flag for creating indexes. And fix type in tests. --- .../data/mongodb/core/index/CompoundIndex.java | 4 ++++ .../org/springframework/data/mongodb/core/index/Index.java | 7 ++++++- .../springframework/data/mongodb/core/index/Indexed.java | 4 ++++ .../index/MongoPersistentEntityIndexResolverUnitTests.java | 6 +++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java index 05cf13f66b..2f618386a1 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java @@ -152,11 +152,15 @@ /** * If {@literal true} the index will be created in the background. + *

+ * NOTE: Since MongoDB 4.2 the background flag is ignored by the server if set. * * @return {@literal false} by default. * @see https://docs.mongodb.org/manual/core/indexes/#background-construction + * @deprecated since 5.0 for removal without replacement. */ + @Deprecated(since = "5.0", forRemoval = true) boolean background() default false; /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java index 91195a40f4..c6f83e2e73 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java @@ -94,10 +94,15 @@ public Index sparse() { /** * Build the index in background (non blocking). + *

+ * NOTE: Since MongoDB 4.2 the background flag is ignored by the server if set. * * @return this. * @since 1.5 - */@Contract("-> this") + * @deprecated since 5.0 for removal without replacement. + */ + @Deprecated(since = "5.0", forRemoval = true) + @Contract("-> this") public Index background() { this.background = true; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java index 0866556c10..de89420c87 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java @@ -123,11 +123,15 @@ /** * If {@literal true} the index will be created in the background. + *

+ * NOTE: Since MongoDB 4.2 the background flag is ignored by the server if set. * * @return {@literal false} by default. + * @deprecated since 5.0 for removal without replacement. * @see https://docs.mongodb.org/manual/core/indexes/#background-construction */ + @Deprecated(since = "5.0", forRemoval = true) boolean background() default false; /** diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java index dda16f7849..92cccb38f7 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java @@ -613,7 +613,7 @@ public void compoundIndexOnSuperClassResolvedCorrectly() { public void compoundIndexDoesNotSpecifyNameWhenUsingGenerateName() { List indexDefinitions = prepareMappingContextAndResolveIndexForType( - ComountIndexWithAutogeneratedName.class); + CompoundIndexWithAutogeneratedName.class); IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); assertThat(indexDefinition.getIndexOptions()) @@ -778,10 +778,10 @@ class SingleCompoundIndex {} class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {} - @Document("ComountIndexWithAutogeneratedName") + @Document("CompoundIndexWithAutogeneratedName") @CompoundIndexes({ @CompoundIndex(useGeneratedName = true, def = "{'foo': 1, 'bar': -1}", background = true, sparse = true, unique = true) }) - class ComountIndexWithAutogeneratedName {} + class CompoundIndexWithAutogeneratedName {} @Document("WithComposedAnnotation") @ComposedCompoundIndex