diff --git a/pom.xml b/pom.xml
index b78554647f..3b04395a67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.1.0-SNAPSHOT
+ 4.1.x-GH-4238-SNAPSHOT
pom
Spring Data MongoDB
diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml
index 1b2a1390e6..567a71316b 100644
--- a/spring-data-mongodb-benchmarks/pom.xml
+++ b/spring-data-mongodb-benchmarks/pom.xml
@@ -7,7 +7,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.1.0-SNAPSHOT
+ 4.1.x-GH-4238-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml
index 8db8d798fb..aeacf70e4f 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
- 4.1.0-SNAPSHOT
+ 4.1.x-GH-4238-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index 9a57f7eb52..663d4037aa 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -13,7 +13,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.1.0-SNAPSHOT
+ 4.1.x-GH-4238-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
index d579e6d034..177783c70b 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
@@ -30,7 +30,6 @@
import org.apache.commons.logging.LogFactory;
import org.bson.Document;
import org.bson.conversions.Bson;
-
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -634,7 +633,8 @@ public MongoCollection createCollection(String collectionName,
}
@Override
- public MongoCollection createView(String name, Class> source, AggregationPipeline pipeline, @Nullable ViewOptions options) {
+ public MongoCollection createView(String name, Class> source, AggregationPipeline pipeline,
+ @Nullable ViewOptions options) {
return createView(name, getCollectionName(source),
queryOperations.createAggregation(Aggregation.newAggregation(source, pipeline.getOperations()), source),
@@ -642,7 +642,8 @@ public MongoCollection createView(String name, Class> source, Aggreg
}
@Override
- public MongoCollection createView(String name, String source, AggregationPipeline pipeline, @Nullable ViewOptions options) {
+ public MongoCollection createView(String name, String source, AggregationPipeline pipeline,
+ @Nullable ViewOptions options) {
return createView(name, source,
queryOperations.createAggregation(Aggregation.newAggregation(pipeline.getOperations()), (Class>) null),
@@ -654,7 +655,8 @@ private MongoCollection createView(String name, String source, Aggrega
return doCreateView(name, source, aggregation.getAggregationPipeline(), options);
}
- protected MongoCollection doCreateView(String name, String source, List pipeline, @Nullable ViewOptions options) {
+ protected MongoCollection doCreateView(String name, String source, List pipeline,
+ @Nullable ViewOptions options) {
CreateViewOptions viewOptions = new CreateViewOptions();
if (options != null) {
@@ -2065,7 +2067,16 @@ protected AggregationResults doAggregate(Aggregation aggregation, String
}
options.getComment().ifPresent(aggregateIterable::comment);
- options.getHint().ifPresent(aggregateIterable::hint);
+ if (options.getHintObject().isPresent()) {
+ Object hintObject = options.getHintObject().get();
+ if (hintObject instanceof String hintString) {
+ aggregateIterable = aggregateIterable.hintString(hintString);
+ } else if (hintObject instanceof Document hintDocument) {
+ aggregateIterable = aggregateIterable.hint(hintDocument);
+ } else {
+ throw new IllegalStateException("Unable to read hint of type %s".formatted(hintObject.getClass()));
+ }
+ }
if (options.hasExecutionTimeLimit()) {
aggregateIterable = aggregateIterable.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
@@ -2124,7 +2135,16 @@ protected Stream aggregateStream(Aggregation aggregation, String collecti
}
options.getComment().ifPresent(cursor::comment);
- options.getHint().ifPresent(cursor::hint);
+ if (options.getHintObject().isPresent()) {
+ Object hintObject = options.getHintObject().get();
+ if (hintObject instanceof String hintString) {
+ cursor = cursor.hintString(hintString);
+ } else if (hintObject instanceof Document hintDocument) {
+ cursor = cursor.hint(hintDocument);
+ } else {
+ throw new IllegalStateException("Unable to read hint of type %s".formatted(hintObject.getClass()));
+ }
+ }
Class> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType()
: null;
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
index ac58269750..d2dd4f6f60 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
@@ -938,7 +938,16 @@ private Flux aggregateAndMap(MongoCollection collection, List operations.forType(inputType).getCollation()) //
.map(Collation::toMongoCollation) //
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java
index e4ef7a7e49..11e42e8682 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationOptions.java
@@ -20,6 +20,7 @@
import org.bson.Document;
import org.springframework.data.mongodb.core.query.Collation;
+import org.springframework.data.mongodb.util.BsonUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -53,7 +54,7 @@ public class AggregationOptions {
private final Optional cursor;
private final Optional collation;
private final Optional comment;
- private final Optional hint;
+ private final Optional