diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java index 24d22bd80..69c6be96e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java @@ -116,7 +116,7 @@ public class DefaultIndexOperations implements IndexOperations { @Override @SuppressWarnings("NullAway") - public String ensureIndex(IndexDefinition indexDefinition) { + public String createIndex(IndexDefinition indexDefinition) { return execute(collection -> { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java index 69ade2e16..4c4ad18b4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java @@ -84,7 +84,7 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @Override @SuppressWarnings("NullAway") - public Mono ensureIndex(IndexDefinition indexDefinition) { + public Mono createIndex(IndexDefinition indexDefinition) { return mongoOperations.execute(collectionName, collection -> { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperations.java index 88e6d7a81..1f8ddf5d7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperations.java @@ -36,19 +36,20 @@ public interface IndexOperations { * @deprecated since 4.5, in favor of {@link #createIndex(IndexDefinition)}. */ @Deprecated(since = "4.5", forRemoval = true) - String ensureIndex(IndexDefinition indexDefinition); + default String ensureIndex(IndexDefinition indexDefinition) { + return createIndex(indexDefinition); + } /** - * Create the index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class. - * If not it will be created. + * Create the index for the provided {@link IndexDefinition} for the collection indicated by the entity class. If the + * index does not exist it will be created. Might error if the collection already defines an index with the same name + * but different settings. * * @param indexDefinition must not be {@literal null}. * @return the index name. * @since 4.5 */ - default String createIndex(IndexDefinition indexDefinition) { - return ensureIndex(indexDefinition); - } + String createIndex(IndexDefinition indexDefinition); /** * Alters the index with given {@literal name}. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperationsAdapter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperationsAdapter.java index 613a3dc4f..5dc33e25d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperationsAdapter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexOperationsAdapter.java @@ -41,8 +41,8 @@ public interface IndexOperationsAdapter extends IndexOperations { return new IndexOperationsAdapter() { @Override - public String ensureIndex(IndexDefinition indexDefinition) { - return reactiveIndexOperations.ensureIndex(indexDefinition).block(); + public String createIndex(IndexDefinition indexDefinition) { + return reactiveIndexOperations.createIndex(indexDefinition).block(); } @Override diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/ReactiveIndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/ReactiveIndexOperations.java index 15b110c08..497862865 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/ReactiveIndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/ReactiveIndexOperations.java @@ -36,19 +36,20 @@ public interface ReactiveIndexOperations { * @deprecated since 4.5, in favor of {@link #createIndex(IndexDefinition)}. */ @Deprecated(since = "4.5", forRemoval = true) - Mono ensureIndex(IndexDefinition indexDefinition); + default Mono ensureIndex(IndexDefinition indexDefinition) { + return createIndex(indexDefinition); + } /** - * Create the index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class. - * If not it will be created. + * Create the index for the provided {@link IndexDefinition} for the collection indicated by the entity class. If the + * index does not exist it will be created. Might error if the collection already defines an index with the same name + * but different settings. * * @param indexDefinition must not be {@literal null}. * @return the index name. * @since 4.5 */ - default Mono createIndex(IndexDefinition indexDefinition) { - return ensureIndex(indexDefinition); - } + Mono createIndex(IndexDefinition indexDefinition); /** * Alters the index with given {@literal name}.