diff --git a/pom.xml b/pom.xml
index 7227da3581..bf0f0ff103 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-SNAPSHOT
pom
Spring Data MongoDB
diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml
index 9baccaa905..3f401adef3 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
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml
index 47a5b7aba7..e6e340fcbe 100644
--- a/spring-data-mongodb-cross-store/pom.xml
+++ b/spring-data-mongodb-cross-store/pom.xml
@@ -6,7 +6,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-SNAPSHOT
../pom.xml
@@ -50,7 +50,7 @@
org.springframework.data
spring-data-mongodb
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-SNAPSHOT
diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml
index e5c865ea08..5e74626582 100644
--- a/spring-data-mongodb-distribution/pom.xml
+++ b/spring-data-mongodb-distribution/pom.xml
@@ -13,7 +13,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index b86dc2808c..348663bf1f 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -11,7 +11,7 @@
org.springframework.data
spring-data-mongodb-parent
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAMONGO-1311-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 f0ac8e53a2..dd152a9170 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
@@ -3279,9 +3279,9 @@ public FindIterable prepare(FindIterable cursor) {
return cursor;
}
+ Meta meta = query.getMeta();
if (query.getSkip() <= 0 && query.getLimit() <= 0 && ObjectUtils.isEmpty(query.getSortObject())
- && !StringUtils.hasText(query.getHint()) && !query.getMeta().hasValues()
- && !query.getCollation().isPresent()) {
+ && !StringUtils.hasText(query.getHint()) && !meta.hasValues() && !query.getCollation().isPresent()) {
return cursor;
}
@@ -3301,18 +3301,33 @@ public FindIterable prepare(FindIterable cursor) {
cursorToUse = cursorToUse.sort(sort);
}
- Document meta = new Document();
if (StringUtils.hasText(query.getHint())) {
- meta.put("$hint", query.getHint());
+ cursorToUse = cursorToUse.hint(Document.parse(query.getHint()));
}
- if (query.getMeta().hasValues()) {
+ if (meta.hasValues()) {
- for (Entry entry : query.getMeta().values()) {
- meta.put(entry.getKey(), entry.getValue());
+ if (StringUtils.hasText(meta.getComment())) {
+ cursorToUse = cursorToUse.comment(meta.getComment());
}
- for (Meta.CursorOption option : query.getMeta().getFlags()) {
+ if (meta.getSnapshot()) {
+ cursorToUse = cursorToUse.snapshot(meta.getSnapshot());
+ }
+
+ if (meta.getMaxScan() != null) {
+ cursorToUse = cursorToUse.maxScan(meta.getMaxScan());
+ }
+
+ if (meta.getMaxTimeMsec() != null) {
+ cursorToUse = cursorToUse.maxTime(meta.getMaxTimeMsec(), TimeUnit.MILLISECONDS);
+ }
+
+ if (meta.getCursorBatchSize() != null) {
+ cursorToUse = cursorToUse.batchSize(meta.getCursorBatchSize());
+ }
+
+ for (Meta.CursorOption option : meta.getFlags()) {
switch (option) {
@@ -3328,7 +3343,6 @@ public FindIterable prepare(FindIterable cursor) {
}
}
- cursorToUse = cursorToUse.modifiers(meta);
} catch (RuntimeException e) {
throw potentiallyConvertRuntimeException(e, exceptionTranslator);
}
@@ -3459,149 +3473,6 @@ public MongoDbFactory getMongoDbFactory() {
return mongoDbFactory;
}
- /**
- * {@link BatchAggregationLoader} is a little helper that can process cursor results returned by an aggregation
- * command execution. On presence of a {@literal nextBatch} indicated by presence of an {@code id} field in the
- * {@code cursor} another {@code getMore} command gets executed reading the next batch of documents until all results
- * are loaded.
- *
- * @author Christoph Strobl
- * @since 1.10
- */
- static class BatchAggregationLoader {
-
- private static final String CURSOR_FIELD = "cursor";
- private static final String RESULT_FIELD = "result";
- private static final String BATCH_SIZE_FIELD = "batchSize";
- private static final String FIRST_BATCH = "firstBatch";
- private static final String NEXT_BATCH = "nextBatch";
- private static final String SERVER_USED = "serverUsed";
- private static final String OK = "ok";
-
- private final MongoTemplate template;
- private final ReadPreference readPreference;
- private final int batchSize;
-
- BatchAggregationLoader(MongoTemplate template, ReadPreference readPreference, int batchSize) {
-
- this.template = template;
- this.readPreference = readPreference;
- this.batchSize = batchSize;
- }
-
- /**
- * Run aggregation command and fetch all results.
- */
- Document aggregate(String collectionName, Aggregation aggregation, AggregationOperationContext context) {
-
- Document command = prepareAggregationCommand(collectionName, aggregation, context, batchSize);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Executing aggregation: {}", serializeToJsonSafely(command));
- }
-
- return mergeAggregationResults(aggregateBatched(command, collectionName, batchSize));
- }
-
- /**
- * Pre process the aggregation command sent to the server by adding {@code cursor} options to match execution on
- * different server versions.
- */
- private static Document prepareAggregationCommand(String collectionName, Aggregation aggregation,
- @Nullable AggregationOperationContext context, int batchSize) {
-
- AggregationOperationContext rootContext = context == null ? Aggregation.DEFAULT_CONTEXT : context;
- Document command = aggregation.toDocument(collectionName, rootContext);
-
- if (!aggregation.getOptions().isExplain()) {
- command.put(CURSOR_FIELD, new Document(BATCH_SIZE_FIELD, batchSize));
- }
-
- return command;
- }
-
- private List aggregateBatched(Document command, String collectionName, int batchSize) {
-
- List results = new ArrayList<>();
-
- Document commandResult = template.executeCommand(command, readPreference);
- results.add(postProcessResult(commandResult));
-
- while (hasNext(commandResult)) {
-
- Document getMore = new Document("getMore", getNextBatchId(commandResult)) //
- .append("collection", collectionName) //
- .append(BATCH_SIZE_FIELD, batchSize);
-
- commandResult = template.executeCommand(getMore, this.readPreference);
- results.add(postProcessResult(commandResult));
- }
-
- return results;
- }
-
- private static Document postProcessResult(Document commandResult) {
-
- if (!commandResult.containsKey(CURSOR_FIELD)) {
- return commandResult;
- }
-
- Document resultObject = new Document(SERVER_USED, commandResult.get(SERVER_USED));
- resultObject.put(OK, commandResult.get(OK));
-
- Document cursor = (Document) commandResult.get(CURSOR_FIELD);
- if (cursor.containsKey(FIRST_BATCH)) {
- resultObject.put(RESULT_FIELD, cursor.get(FIRST_BATCH));
- } else {
- resultObject.put(RESULT_FIELD, cursor.get(NEXT_BATCH));
- }
-
- return resultObject;
- }
-
- private static Document mergeAggregationResults(List batchResults) {
-
- if (batchResults.size() == 1) {
- return batchResults.iterator().next();
- }
-
- Document commandResult = new Document();
- List