DATAMONGO-2536 - Polishing.
Encapsulate skipResults in AggregationOptions. Reformat code. Add override Javadoc. Original pull request: #876.
This commit is contained in:
@@ -28,6 +28,7 @@ import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -62,7 +63,6 @@ import org.springframework.data.mongodb.core.QueryOperations.UpdateContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOptions.ResultOptions;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||
import org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
|
||||
@@ -2132,7 +2132,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
List<Document> rawResult = new ArrayList<>();
|
||||
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType()
|
||||
Class<?> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation<?>) aggregation).getInputType()
|
||||
: null;
|
||||
|
||||
Optional<Collation> collation = Optionals.firstNonEmpty(options::getCollation,
|
||||
@@ -2153,10 +2153,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
aggregateIterable = aggregateIterable.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
if(ResultOptions.SKIP.equals(options.resultOptions())) {
|
||||
if (options.isSkipResults()) {
|
||||
|
||||
// toCollection only allowed for $out and $merge if those are the last stages
|
||||
if(aggregation.getPipeline().isOutOrMerge()) {
|
||||
if (aggregation.getPipeline().isOutOrMerge()) {
|
||||
aggregateIterable.toCollection();
|
||||
} else {
|
||||
aggregateIterable.first();
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bson.BsonValue;
|
||||
@@ -37,6 +36,7 @@ import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -69,7 +69,6 @@ import org.springframework.data.mongodb.core.QueryOperations.UpdateContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationOptions.ResultOptions;
|
||||
import org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext;
|
||||
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
|
||||
@@ -1006,11 +1005,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
ReadDocumentCallback<O> readCallback = new ReadDocumentCallback<>(mongoConverter, outputType, collectionName);
|
||||
return execute(collectionName, collection -> aggregateAndMap(collection, pipeline, () -> aggregation.getPipeline().isOutOrMerge(), options, readCallback,
|
||||
aggregation instanceof TypedAggregation ? ((TypedAggregation) aggregation).getInputType() : null));
|
||||
return execute(collectionName,
|
||||
collection -> aggregateAndMap(collection, pipeline, aggregation.getPipeline().isOutOrMerge(), options,
|
||||
readCallback,
|
||||
aggregation instanceof TypedAggregation ? ((TypedAggregation<?>) aggregation).getInputType() : null));
|
||||
}
|
||||
|
||||
private <O> Flux<O> aggregateAndMap(MongoCollection<Document> collection, List<Document> pipeline, Supplier<Boolean> isOutOrMerge,
|
||||
private <O> Flux<O> aggregateAndMap(MongoCollection<Document> collection, List<Document> pipeline,
|
||||
boolean isOutOrMerge,
|
||||
AggregationOptions options, ReadDocumentCallback<O> readCallback, @Nullable Class<?> inputType) {
|
||||
|
||||
AggregatePublisher<Document> cursor = collection.aggregate(pipeline, Document.class)
|
||||
@@ -1030,11 +1032,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
cursor = cursor.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
if (ResultOptions.SKIP.equals(options.resultOptions())) {
|
||||
if (isOutOrMerge.get()) {
|
||||
return Flux.from(cursor.toCollection()).map(it -> (O) it);
|
||||
}
|
||||
return Flux.from(cursor.first()).thenMany(Mono.empty());
|
||||
if (options.isSkipResults()) {
|
||||
return (isOutOrMerge ? Flux.from(cursor.toCollection()) : Flux.from(cursor.first())).thenMany(Mono.empty());
|
||||
}
|
||||
|
||||
return Flux.from(cursor).concatMap(readCallback::doWith);
|
||||
|
||||
@@ -99,6 +99,10 @@ public class AddFieldsOperation extends DocumentEnhancingOperation {
|
||||
return new AddFieldsOperationBuilder(getValueMap());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.DocumentEnhancingOperation#mongoOperator()
|
||||
*/
|
||||
@Override
|
||||
protected String mongoOperator() {
|
||||
return "$addFields";
|
||||
|
||||
@@ -645,9 +645,9 @@ public class Aggregation {
|
||||
/**
|
||||
* Creates a new {@link RedactOperation} that can restrict the content of a document based on information stored
|
||||
* within the document itself.
|
||||
*
|
||||
*
|
||||
* <pre class="code">
|
||||
*
|
||||
*
|
||||
* Aggregation.redact(ConditionalOperators.when(Criteria.where("level").is(5)) //
|
||||
* .then(RedactOperation.PRUNE) //
|
||||
* .otherwise(RedactOperation.DESCEND));
|
||||
@@ -705,6 +705,10 @@ public class Aggregation {
|
||||
return pipeline.toDocuments(rootContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link AggregationPipeline}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public AggregationPipeline getPipeline() {
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,14 @@ public interface AggregationOperation {
|
||||
return Collections.singletonList(toDocument(context));
|
||||
}
|
||||
|
||||
default String operator() {
|
||||
/**
|
||||
* Return the MongoDB operator that is used for this {@link AggregationOperation}. Aggregation operations should
|
||||
* implement this method to avoid document rendering.
|
||||
*
|
||||
* @return the operator used for this {@link AggregationOperation}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
default String getOperator() {
|
||||
return toDocument(Aggregation.DEFAULT_CONTEXT).keySet().iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,11 +221,12 @@ public class AggregationOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link ResultOptions} to be used when running the {@link Aggregation}. Never {@literal null}.
|
||||
* @since 3.0
|
||||
* @return {@literal true} to skip results when running an aggregation. Useful in combination with {@code $merge} or
|
||||
* {@code $out}.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public ResultOptions resultOptions() {
|
||||
return resultOptions;
|
||||
public boolean isSkipResults() {
|
||||
return ResultOptions.SKIP.equals(resultOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,7 +416,7 @@ public class AggregationOptions {
|
||||
* option allows to execute the aggregation without having the cursor return the operation result.
|
||||
*
|
||||
* @return this.
|
||||
* @since 3.0
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Builder skipOutput() {
|
||||
|
||||
@@ -445,7 +446,7 @@ public class AggregationOptions {
|
||||
/**
|
||||
* @since 3.0
|
||||
*/
|
||||
public enum ResultOptions {
|
||||
private enum ResultOptions {
|
||||
|
||||
/**
|
||||
* Just do it!, and do not read the operation result.
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.Assert;
|
||||
* The {@link AggregationPipeline} holds the collection of {@link AggregationOperation aggregation stages}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 3.1
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public class AggregationPipeline {
|
||||
|
||||
@@ -86,7 +86,7 @@ public class AggregationPipeline {
|
||||
return false;
|
||||
}
|
||||
|
||||
String operator = pipeline.get(pipeline.size() - 1).operator();
|
||||
String operator = pipeline.get(pipeline.size() - 1).getOperator();
|
||||
return operator.equals("$out") || operator.equals("$merge");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketAutoOperation.BucketAutoOperationOutputBuilder;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.OutputBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $bucketAuto}-operation. <br />
|
||||
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into a
|
||||
@@ -106,11 +105,15 @@ public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperat
|
||||
|
||||
options.putAll(super.toDocument(context));
|
||||
|
||||
return new Document(operator(), options);
|
||||
return new Document(getOperator(), options);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$bucketAuto";
|
||||
}
|
||||
|
||||
|
||||
@@ -20,21 +20,19 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperation.BucketOperationOutputBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $bucket}-operation. <br />
|
||||
*
|
||||
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into
|
||||
* groups, called buckets, based on a specified expression and bucket boundaries. <br />
|
||||
*
|
||||
* We recommend to use the static factory method {@link Aggregation#bucket(String)} instead of creating instances of
|
||||
* this class directly.
|
||||
*
|
||||
* @see <a href="https://docs.mongodb.org/manual/reference/aggregation/bucket/">https://docs.mongodb.org/manual/reference/aggregation/bucket/</a>
|
||||
* @see <a href=
|
||||
* "https://docs.mongodb.org/manual/reference/aggregation/bucket/">https://docs.mongodb.org/manual/reference/aggregation/bucket/</a>
|
||||
* @see BucketOperationSupport
|
||||
* @author Mark Paluch
|
||||
* @since 1.10
|
||||
@@ -103,11 +101,15 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
|
||||
options.putAll(super.toDocument(context));
|
||||
|
||||
return new Document(operator(), options);
|
||||
return new Document(getOperator(), options);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$bucket";
|
||||
}
|
||||
|
||||
@@ -209,8 +211,8 @@ public class BucketOperation extends BucketOperationSupport<BucketOperation, Buc
|
||||
extends ExpressionBucketOperationBuilderSupport<BucketOperationOutputBuilder, BucketOperation> {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ExpressionBucketOperationBuilderSupport} for the given value, {@link BucketOperation}
|
||||
* and parameters.
|
||||
* Creates a new {@link ExpressionBucketOperationBuilderSupport} for the given value, {@link BucketOperation} and
|
||||
* parameters.
|
||||
*
|
||||
* @param expression must not be {@literal null}.
|
||||
* @param operation must not be {@literal null}.
|
||||
|
||||
@@ -49,11 +49,11 @@ public class CountOperation implements FieldsExposingAggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), fieldName);
|
||||
return new Document(getOperator(), fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$count";
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,12 @@ abstract class DocumentEnhancingOperation implements InheritsFieldsAggregationOp
|
||||
*/
|
||||
protected abstract String mongoOperator();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return mongoOperator();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,11 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.Output;
|
||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Encapsulates the aggregation framework {@code $facet}-operation. <br />
|
||||
* Facet of {@link AggregationOperation}s to be used in an {@link Aggregation}. Processes multiple
|
||||
@@ -84,11 +83,15 @@ public class FacetOperation implements FieldsExposingAggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), facets.toDocument(context));
|
||||
return new Document(getOperator(), facets.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$facet";
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.NumberUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -95,25 +93,26 @@ public class GeoNearOperation implements AggregationOperation {
|
||||
|
||||
Document command = context.getMappedObject(nearQuery.toDocument());
|
||||
|
||||
if(command.containsKey("query")) {
|
||||
if (command.containsKey("query")) {
|
||||
command.replace("query", context.getMappedObject(command.get("query", Document.class)));
|
||||
}
|
||||
|
||||
if(command.containsKey("collation")) {
|
||||
command.remove("collation");
|
||||
}
|
||||
|
||||
command.remove("collation");
|
||||
command.put("distanceField", distanceField);
|
||||
|
||||
if (StringUtils.hasText(indexKey)) {
|
||||
command.put("key", indexKey);
|
||||
}
|
||||
|
||||
return new Document(operator(), command);
|
||||
return new Document(getOperator(), command);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$geoNear";
|
||||
}
|
||||
|
||||
@@ -130,11 +129,11 @@ public class GeoNearOperation implements AggregationOperation {
|
||||
List<Document> stages = new ArrayList<>();
|
||||
stages.add(command);
|
||||
|
||||
if(nearQuery.getSkip() != null && nearQuery.getSkip() > 0){
|
||||
if (nearQuery.getSkip() != null && nearQuery.getSkip() > 0) {
|
||||
stages.add(new Document("$skip", nearQuery.getSkip()));
|
||||
}
|
||||
|
||||
if(limit != null) {
|
||||
if (limit != null) {
|
||||
stages.add(new Document("$limit", limit.longValue()));
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +119,11 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
graphLookup.put("restrictSearchWithMatch", context.getMappedObject(restrictSearchWithMatch.getCriteriaObject()));
|
||||
}
|
||||
|
||||
return new Document(operator(), graphLookup);
|
||||
return new Document(getOperator(), graphLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$graphLookup";
|
||||
}
|
||||
|
||||
|
||||
@@ -429,11 +429,15 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
|
||||
operationObject.putAll(operation.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document(operator(), operationObject);
|
||||
return new Document(getOperator(), operationObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$group";
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,15 @@ public class LimitOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), Long.valueOf(maxElements));
|
||||
return new Document(getOperator(), Long.valueOf(maxElements));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$limit";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ public class LiteralOperators {
|
||||
super(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression#getMongoMethod()
|
||||
*/
|
||||
@Override
|
||||
protected String getMongoMethod() {
|
||||
return "$literal";
|
||||
|
||||
@@ -83,11 +83,15 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
lookupObject.append("foreignField", foreignField.getTarget());
|
||||
lookupObject.append("as", as.getTarget());
|
||||
|
||||
return new Document(operator(), lookupObject);
|
||||
return new Document(getOperator(), lookupObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$lookup";
|
||||
}
|
||||
|
||||
@@ -173,8 +177,7 @@ public class LookupOperation implements FieldsExposingAggregationOperation, Inhe
|
||||
|
||||
Assert.hasText(name, "'As' must not be null or empty!");
|
||||
as = new ExposedField(Fields.field(name), true);
|
||||
return new LookupOperation(from, localField, foreignField,
|
||||
as);
|
||||
return new LookupOperation(from, localField, foreignField, as);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,8 @@ import org.springframework.util.Assert;
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/">MongoDB Aggregation Framework: $match</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/match/">MongoDB Aggregation Framework:
|
||||
* $match</a>
|
||||
*/
|
||||
public class MatchOperation implements AggregationOperation {
|
||||
|
||||
@@ -53,11 +54,15 @@ public class MatchOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), context.getMappedObject(criteriaDefinition.getCriteriaObject()));
|
||||
return new Document(getOperator(), context.getMappedObject(criteriaDefinition.getCriteriaObject()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$match";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
if (isJustCollection()) {
|
||||
return new Document(operator(), into.collection);
|
||||
return new Document(getOperator(), into.collection);
|
||||
}
|
||||
|
||||
Document $merge = new Document();
|
||||
@@ -122,11 +122,15 @@ public class MergeOperation implements FieldsExposingAggregationOperation, Inher
|
||||
$merge.putAll(whenNotMatched.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document(operator(), $merge);
|
||||
return new Document(getOperator(), $merge);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$merge";
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -211,11 +210,15 @@ public class OutOperation implements AggregationOperation {
|
||||
$out.append("uniqueKey", uniqueKey);
|
||||
}
|
||||
|
||||
return new Document(operator(), $out);
|
||||
return new Document(getOperator(), $out);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$out";
|
||||
}
|
||||
|
||||
|
||||
@@ -261,11 +261,15 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
fieldObject.putAll(projection.toDocument(context));
|
||||
}
|
||||
|
||||
return new Document(operator(), fieldObject);
|
||||
return new Document(getOperator(), fieldObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$project";
|
||||
}
|
||||
|
||||
@@ -1553,7 +1557,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
final Field aliasedField = Fields.field(alias, this.field.getName());
|
||||
return new OperationProjection(aliasedField, operation, values.toArray()) {
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.OperationProjection#getField()
|
||||
*/
|
||||
@@ -1754,7 +1758,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.Projection#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@@ -1882,7 +1886,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
this.projections = projections;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ProjectionOperation.Projection#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
|
||||
@@ -74,11 +74,15 @@ public class RedactOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), condition.toDocument(context));
|
||||
return new Document(getOperator(), condition.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$redact";
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,12 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
||||
return new Document("$replaceRoot", new Document("newRoot", getReplacement().toDocumentExpression(context)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$replaceRoot";
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,15 @@ public class SampleOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), new Document("size", this.sampleSize));
|
||||
return new Document(getOperator(), new Document("size", this.sampleSize));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$sample";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,10 @@ public class SetOperation extends DocumentEnhancingOperation {
|
||||
return new FieldAppender(getValueMap());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.DocumentEnhancingOperation#mongoOperator()
|
||||
*/
|
||||
@Override
|
||||
protected String mongoOperator() {
|
||||
return "$set";
|
||||
|
||||
@@ -28,7 +28,8 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/skip/">MongoDB Aggregation Framework: $skip</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/skip/">MongoDB Aggregation Framework:
|
||||
* $skip</a>
|
||||
*/
|
||||
public class SkipOperation implements AggregationOperation {
|
||||
|
||||
@@ -51,11 +52,15 @@ public class SkipOperation implements AggregationOperation {
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(operator(), skipCount);
|
||||
return new Document(getOperator(), skipCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$skip";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,19 +67,23 @@ public class SortByCountOperation implements AggregationOperation {
|
||||
this.groupByField = null;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#toDocument(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
return new Document(operator(), groupByExpression == null ? context.getReference(groupByField).toString()
|
||||
return new Document(getOperator(), groupByExpression == null ? context.getReference(groupByField).toString()
|
||||
: groupByExpression.toDocument(context));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$sortByCount";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ import org.springframework.util.Assert;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/sort/">MongoDB Aggregation Framework: $sort</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/sort/">MongoDB Aggregation Framework:
|
||||
* $sort</a>
|
||||
*/
|
||||
public class SortOperation implements AggregationOperation {
|
||||
|
||||
@@ -74,11 +75,15 @@ public class SortOperation implements AggregationOperation {
|
||||
object.put(reference.getRaw(), order.isAscending() ? 1 : -1);
|
||||
}
|
||||
|
||||
return new Document(operator(), object);
|
||||
return new Document(getOperator(), object);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$sort";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
|
||||
/**
|
||||
* Create new instance of {@link UnsetOperation}.
|
||||
*
|
||||
*
|
||||
* @param fields must not be {@literal null}.
|
||||
*/
|
||||
public UnsetOperation(Collection<Object> fields) {
|
||||
@@ -117,15 +117,19 @@ public class UnsetOperation implements InheritsFieldsAggregationOperation {
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
if (fields.size() == 1) {
|
||||
return new Document(operator(), computeFieldName(fields.iterator().next(), context));
|
||||
return new Document(getOperator(), computeFieldName(fields.iterator().next(), context));
|
||||
}
|
||||
|
||||
return new Document(operator(),
|
||||
return new Document(getOperator(),
|
||||
fields.stream().map(it -> computeFieldName(it, context)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$unset";
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/">MongoDB Aggregation Framework: $unwind</a>
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/">MongoDB Aggregation Framework:
|
||||
* $unwind</a>
|
||||
*/
|
||||
public class UnwindOperation
|
||||
implements AggregationOperation, FieldsExposingAggregationOperation.InheritsFieldsAggregationOperation {
|
||||
@@ -94,7 +95,7 @@ public class UnwindOperation
|
||||
String path = context.getReference(field).toString();
|
||||
|
||||
if (!preserveNullAndEmptyArrays && arrayIndex == null) {
|
||||
return new Document(operator(), path);
|
||||
return new Document(getOperator(), path);
|
||||
}
|
||||
|
||||
Document unwindArgs = new Document();
|
||||
@@ -104,11 +105,15 @@ public class UnwindOperation
|
||||
}
|
||||
unwindArgs.put("preserveNullAndEmptyArrays", preserveNullAndEmptyArrays);
|
||||
|
||||
return new Document(operator(), unwindArgs);
|
||||
return new Document(getOperator(), unwindArgs);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperation#getOperator()
|
||||
*/
|
||||
@Override
|
||||
public String operator() {
|
||||
public String getOperator() {
|
||||
return "$unwind";
|
||||
}
|
||||
|
||||
|
||||
@@ -99,17 +99,17 @@ public class AggregationTests {
|
||||
private static boolean initialized = false;
|
||||
|
||||
@Template //
|
||||
static MongoTestTemplate mongoTemplate;
|
||||
private static MongoTestTemplate mongoTemplate;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
|
||||
cleanDb();
|
||||
initSampleDataIfNecessary();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
void cleanUp() {
|
||||
cleanDb();
|
||||
}
|
||||
|
||||
@@ -167,25 +167,25 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldHandleMissingInputCollection() {
|
||||
void shouldHandleMissingInputCollection() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> mongoTemplate.aggregate(newAggregation(), (String) null, TagCount.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldHandleMissingAggregationPipeline() {
|
||||
void shouldHandleMissingAggregationPipeline() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> mongoTemplate.aggregate(null, INPUT_COLLECTION, TagCount.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldHandleMissingEntityClass() {
|
||||
void shouldHandleMissingEntityClass() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> mongoTemplate.aggregate(newAggregation(), INPUT_COLLECTION, null));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldAggregate() {
|
||||
void shouldAggregate() {
|
||||
|
||||
createTagDocuments();
|
||||
|
||||
@@ -214,7 +214,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void shouldAggregateAndStream() {
|
||||
void shouldAggregateAndStream() {
|
||||
|
||||
createTagDocuments();
|
||||
|
||||
@@ -243,7 +243,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldAggregateEmptyCollection() {
|
||||
void shouldAggregateEmptyCollection() {
|
||||
|
||||
Aggregation aggregation = newAggregation(//
|
||||
project("tags"), //
|
||||
@@ -266,7 +266,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void shouldAggregateEmptyCollectionAndStream() {
|
||||
void shouldAggregateEmptyCollectionAndStream() {
|
||||
|
||||
Aggregation aggregation = newAggregation(//
|
||||
project("tags"), //
|
||||
@@ -289,7 +289,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1391
|
||||
public void shouldUnwindWithIndex() {
|
||||
void shouldUnwindWithIndex() {
|
||||
|
||||
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
|
||||
|
||||
@@ -315,7 +315,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1391
|
||||
public void shouldUnwindPreserveEmpty() {
|
||||
void shouldUnwindPreserveEmpty() {
|
||||
|
||||
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
|
||||
|
||||
@@ -341,7 +341,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void shouldDetectResultMismatch() {
|
||||
void shouldDetectResultMismatch() {
|
||||
|
||||
createTagDocuments();
|
||||
|
||||
@@ -366,7 +366,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void shouldDetectResultMismatchWhileStreaming() {
|
||||
void shouldDetectResultMismatchWhileStreaming() {
|
||||
|
||||
createTagDocuments();
|
||||
|
||||
@@ -391,7 +391,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void complexAggregationFrameworkUsageLargestAndSmallestCitiesByState() {
|
||||
void complexAggregationFrameworkUsageLargestAndSmallestCitiesByState() {
|
||||
/*
|
||||
//complex mongodb aggregation framework example from https://docs.mongodb.org/manual/tutorial/aggregation-examples/#largest-and-smallest-cities-by-state
|
||||
db.zipInfo.aggregate(
|
||||
@@ -499,11 +499,11 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void findStatesWithPopulationOver10MillionAggregationExample() {
|
||||
void findStatesWithPopulationOver10MillionAggregationExample() {
|
||||
/*
|
||||
//complex mongodb aggregation framework example from
|
||||
https://docs.mongodb.org/manual/tutorial/aggregation-examples/#largest-and-smallest-cities-by-state
|
||||
|
||||
|
||||
db.zipcodes.aggregate(
|
||||
{
|
||||
$group: {
|
||||
@@ -549,7 +549,7 @@ public class AggregationTests {
|
||||
* Framework: $cond</a>
|
||||
*/
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingConditionalProjectionToCalculateDiscount() {
|
||||
void aggregationUsingConditionalProjectionToCalculateDiscount() {
|
||||
|
||||
/*
|
||||
db.inventory.aggregate(
|
||||
@@ -602,7 +602,7 @@ public class AggregationTests {
|
||||
* Framework: $ifNull</a>
|
||||
*/
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingIfNullToProjectSaneDefaults() {
|
||||
void aggregationUsingIfNullToProjectSaneDefaults() {
|
||||
|
||||
/*
|
||||
db.inventory.aggregate(
|
||||
@@ -642,7 +642,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingConditionalProjection() {
|
||||
void aggregationUsingConditionalProjection() {
|
||||
|
||||
TypedAggregation<ZipInfo> aggregation = newAggregation(ZipInfo.class, //
|
||||
project() //
|
||||
@@ -664,7 +664,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingNestedConditionalProjection() {
|
||||
void aggregationUsingNestedConditionalProjection() {
|
||||
|
||||
TypedAggregation<ZipInfo> aggregation = newAggregation(ZipInfo.class, //
|
||||
project() //
|
||||
@@ -687,7 +687,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingIfNullProjection() {
|
||||
void aggregationUsingIfNullProjection() {
|
||||
|
||||
mongoTemplate.insert(new LineItem("id", "caption", 0));
|
||||
mongoTemplate.insert(new LineItem("idonly", null, 0));
|
||||
@@ -711,7 +711,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-861
|
||||
public void aggregationUsingIfNullReplaceWithFieldReferenceProjection() {
|
||||
void aggregationUsingIfNullReplaceWithFieldReferenceProjection() {
|
||||
|
||||
mongoTemplate.insert(new LineItem("id", "caption", 0));
|
||||
mongoTemplate.insert(new LineItem("idonly", null, 0));
|
||||
@@ -735,7 +735,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-861
|
||||
public void shouldAllowGroupingUsingConditionalExpressions() {
|
||||
void shouldAllowGroupingUsingConditionalExpressions() {
|
||||
|
||||
mongoTemplate.dropCollection(CarPerson.class);
|
||||
|
||||
@@ -779,7 +779,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1784, DATAMONGO-2264
|
||||
public void shouldAllowSumUsingConditionalExpressions() {
|
||||
void shouldAllowSumUsingConditionalExpressions() {
|
||||
|
||||
mongoTemplate.dropCollection(CarPerson.class);
|
||||
|
||||
@@ -827,7 +827,7 @@ public class AggregationTests {
|
||||
* the Five Most Common “Likes”</a>
|
||||
*/
|
||||
@Test // DATAMONGO-586
|
||||
public void returnFiveMostCommonLikesAggregationFrameworkExample() {
|
||||
void returnFiveMostCommonLikesAggregationFrameworkExample() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -848,7 +848,7 @@ public class AggregationTests {
|
||||
assertLikeStats(result.getMappedResults().get(4), "e", 3);
|
||||
}
|
||||
|
||||
protected TypedAggregation<UserWithLikes> createUsersWithCommonLikesAggregation() {
|
||||
TypedAggregation<UserWithLikes> createUsersWithCommonLikesAggregation() {
|
||||
return newAggregation(UserWithLikes.class, //
|
||||
unwind("likes"), //
|
||||
group("likes").count().as("number"), //
|
||||
@@ -859,7 +859,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
public void arithmenticOperatorsInProjectionExample() {
|
||||
void arithmenticOperatorsInProjectionExample() {
|
||||
|
||||
Product product = new Product("P1", "A", 1.99, 3, 0.05, 0.19);
|
||||
mongoTemplate.insert(product);
|
||||
@@ -902,7 +902,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-774
|
||||
public void expressionsInProjectionExample() {
|
||||
void expressionsInProjectionExample() {
|
||||
|
||||
Product product = new Product("P1", "A", 1.99, 3, 0.05, 0.19);
|
||||
mongoTemplate.insert(product);
|
||||
@@ -934,7 +934,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-774
|
||||
public void stringExpressionsInProjectionExample() {
|
||||
void stringExpressionsInProjectionExample() {
|
||||
|
||||
Product product = new Product("P1", "A", 1.99, 3, 0.05, 0.19);
|
||||
mongoTemplate.insert(product);
|
||||
@@ -954,7 +954,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-774
|
||||
public void expressionsInProjectionExampleShowcase() {
|
||||
void expressionsInProjectionExampleShowcase() {
|
||||
|
||||
Product product = new Product("P1", "A", 1.99, 3, 0.05, 0.19);
|
||||
mongoTemplate.insert(product);
|
||||
@@ -983,7 +983,7 @@ public class AggregationTests {
|
||||
* Data MongoDB - Aggregation Framework - invalid reference in group Operation</a>
|
||||
*/
|
||||
@Test // DATAMONGO-753
|
||||
public void allowsNestedFieldReferencesAsGroupIdsInGroupExpressions() {
|
||||
void allowsNestedFieldReferencesAsGroupIdsInGroupExpressions() {
|
||||
|
||||
mongoTemplate.insert(new DATAMONGO753().withPDs(new PD("A", 1), new PD("B", 1), new PD("C", 1)));
|
||||
mongoTemplate.insert(new DATAMONGO753().withPDs(new PD("B", 1), new PD("B", 1), new PD("C", 1)));
|
||||
@@ -1013,7 +1013,7 @@ public class AggregationTests {
|
||||
* Data MongoDB - Aggregation Framework - invalid reference in group Operation</a>
|
||||
*/
|
||||
@Test // DATAMONGO-753
|
||||
public void aliasesNestedFieldInProjectionImmediately() {
|
||||
void aliasesNestedFieldInProjectionImmediately() {
|
||||
|
||||
mongoTemplate.insert(new DATAMONGO753().withPDs(new PD("A", 1), new PD("B", 1), new PD("C", 1)));
|
||||
mongoTemplate.insert(new DATAMONGO753().withPDs(new PD("B", 1), new PD("B", 1), new PD("C", 1)));
|
||||
@@ -1032,7 +1032,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-774
|
||||
public void shouldPerformDateProjectionOperatorsCorrectly() throws ParseException {
|
||||
void shouldPerformDateProjectionOperatorsCorrectly() throws ParseException {
|
||||
|
||||
Data data = new Data();
|
||||
data.stringValue = "ABC";
|
||||
@@ -1058,7 +1058,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-774
|
||||
public void shouldPerformStringProjectionOperatorsCorrectly() throws ParseException {
|
||||
void shouldPerformStringProjectionOperatorsCorrectly() throws ParseException {
|
||||
|
||||
Data data = new Data();
|
||||
data.dateValue = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSZ").parse("29.08.1983 12:34:56.789+0000");
|
||||
@@ -1094,7 +1094,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1550
|
||||
public void shouldPerformReplaceRootOperatorCorrectly() throws ParseException {
|
||||
void shouldPerformReplaceRootOperatorCorrectly() throws ParseException {
|
||||
|
||||
Data data = new Data();
|
||||
DataItem dataItem = new DataItem();
|
||||
@@ -1115,7 +1115,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-788, DATAMONGO-2264
|
||||
public void referencesToGroupIdsShouldBeRenderedProperly() {
|
||||
void referencesToGroupIdsShouldBeRenderedProperly() {
|
||||
|
||||
mongoTemplate.insert(new DATAMONGO788(1, 1));
|
||||
mongoTemplate.insert(new DATAMONGO788(1, 1));
|
||||
@@ -1142,7 +1142,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-806
|
||||
public void shouldAllowGroupByIdFields() {
|
||||
void shouldAllowGroupByIdFields() {
|
||||
|
||||
mongoTemplate.dropCollection(User.class);
|
||||
|
||||
@@ -1173,7 +1173,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-840
|
||||
public void shouldAggregateOrderDataToAnInvoice() {
|
||||
void shouldAggregateOrderDataToAnInvoice() {
|
||||
|
||||
mongoTemplate.dropCollection(Order.class);
|
||||
|
||||
@@ -1210,7 +1210,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-924
|
||||
public void shouldAllowGroupingByAliasedFieldDefinedInFormerAggregationStage() {
|
||||
void shouldAllowGroupingByAliasedFieldDefinedInFormerAggregationStage() {
|
||||
|
||||
mongoTemplate.dropCollection(CarPerson.class);
|
||||
|
||||
@@ -1241,7 +1241,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-960
|
||||
public void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabled() {
|
||||
void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabled() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -1264,7 +1264,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabledWhileStreaming() {
|
||||
void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabledWhileStreaming() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -1290,7 +1290,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-960
|
||||
public void returnFiveMostCommonLikesShouldReturnStageExecutionInformationWithExplainOptionEnabled() {
|
||||
void returnFiveMostCommonLikesShouldReturnStageExecutionInformationWithExplainOptionEnabled() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -1308,7 +1308,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-954, DATAMONGO-2264
|
||||
public void shouldSupportReturningCurrentAggregationRoot() {
|
||||
void shouldSupportReturningCurrentAggregationRoot() {
|
||||
|
||||
mongoTemplate.save(new Person("p1_first", "p1_last", 25));
|
||||
mongoTemplate.save(new Person("p2_first", "p2_last", 32));
|
||||
@@ -1333,7 +1333,7 @@ public class AggregationTests {
|
||||
* {@link https://stackoverflow.com/questions/24185987/using-root-inside-spring-data-mongodb-for-retrieving-whole-document}
|
||||
*/
|
||||
@Test // DATAMONGO-954, DATAMONGO-2264
|
||||
public void shouldSupportReturningCurrentAggregationRootInReference() {
|
||||
void shouldSupportReturningCurrentAggregationRootInReference() {
|
||||
|
||||
mongoTemplate.save(new Reservation("0123", "42", 100));
|
||||
mongoTemplate.save(new Reservation("0360", "43", 200));
|
||||
@@ -1352,7 +1352,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1549
|
||||
public void shouldApplyCountCorrectly() {
|
||||
void shouldApplyCountCorrectly() {
|
||||
|
||||
mongoTemplate.save(new Reservation("0123", "42", 100));
|
||||
mongoTemplate.save(new Reservation("0360", "43", 200));
|
||||
@@ -1371,7 +1371,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-975
|
||||
public void shouldRetrieveDateTimeFragementsCorrectly() throws Exception {
|
||||
void shouldRetrieveDateTimeFragementsCorrectly() throws Exception {
|
||||
|
||||
mongoTemplate.dropCollection(ObjectWithDate.class);
|
||||
|
||||
@@ -1424,7 +1424,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1127
|
||||
public void shouldSupportGeoNearQueriesForAggregationWithDistanceField() {
|
||||
void shouldSupportGeoNearQueriesForAggregationWithDistanceField() {
|
||||
|
||||
mongoTemplate.insertAll(Arrays.asList(TestEntities.geolocation().pennStation(),
|
||||
TestEntities.geolocation().tenGenOffice(), TestEntities.geolocation().flatironBuilding()));
|
||||
@@ -1444,7 +1444,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1348
|
||||
public void shouldSupportGeoJsonInGeoNearQueriesForAggregationWithDistanceField() {
|
||||
void shouldSupportGeoJsonInGeoNearQueriesForAggregationWithDistanceField() {
|
||||
|
||||
mongoTemplate.insert(new Venue("Penn Station", -73.99408, 40.75057));
|
||||
mongoTemplate.insert(new Venue("10gen Office", -73.99171, 40.738868));
|
||||
@@ -1466,7 +1466,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1348
|
||||
public void shouldSupportGeoJsonInGeoNearQueriesForAggregationWithDistanceFieldInMiles() {
|
||||
void shouldSupportGeoJsonInGeoNearQueriesForAggregationWithDistanceFieldInMiles() {
|
||||
|
||||
mongoTemplate.insert(new Venue("Penn Station", -73.99408, 40.75057));
|
||||
mongoTemplate.insert(new Venue("10gen Office", -73.99171, 40.738868));
|
||||
@@ -1489,7 +1489,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1133
|
||||
public void shouldHonorFieldAliasesForFieldReferences() {
|
||||
void shouldHonorFieldAliasesForFieldReferences() {
|
||||
|
||||
mongoTemplate.insert(new MeterData("m1", "counter1", 42));
|
||||
mongoTemplate.insert(new MeterData("m1", "counter1", 13));
|
||||
@@ -1509,7 +1509,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1326
|
||||
public void shouldLookupPeopleCorectly() {
|
||||
void shouldLookupPeopleCorectly() {
|
||||
|
||||
createUsersWithReferencedPersons();
|
||||
|
||||
@@ -1528,7 +1528,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1326
|
||||
public void shouldGroupByAndLookupPeopleCorectly() {
|
||||
void shouldGroupByAndLookupPeopleCorectly() {
|
||||
|
||||
createUsersWithReferencedPersons();
|
||||
|
||||
@@ -1549,7 +1549,7 @@ public class AggregationTests {
|
||||
|
||||
@Test // DATAMONGO-1418, DATAMONGO-1824
|
||||
@MongoVersion(asOf = "2.6")
|
||||
public void shouldCreateOutputCollection() {
|
||||
void shouldCreateOutputCollection() {
|
||||
|
||||
createPersonDocuments();
|
||||
|
||||
@@ -1573,7 +1573,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void shouldCreateOutputCollectionWhileStreaming() {
|
||||
void shouldCreateOutputCollectionWhileStreaming() {
|
||||
|
||||
createPersonDocuments();
|
||||
|
||||
@@ -1595,7 +1595,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1637
|
||||
public void shouldReturnDocumentsWithOutputCollectionWhileStreaming() {
|
||||
void shouldReturnDocumentsWithOutputCollectionWhileStreaming() {
|
||||
|
||||
createPersonDocuments();
|
||||
|
||||
@@ -1626,7 +1626,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1418, DATAMONGO-2536
|
||||
public void outShouldOutBeTheLastOperation() {
|
||||
void outShouldOutBeTheLastOperation() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> newAggregation(match(new Criteria()), //
|
||||
group("field1").count().as("totalCount"), //
|
||||
out("collection1"), //
|
||||
@@ -1634,7 +1634,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1325
|
||||
public void shouldApplySampleCorrectly() {
|
||||
void shouldApplySampleCorrectly() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -1651,7 +1651,7 @@ public class AggregationTests {
|
||||
|
||||
@Test // DATAMONGO-1457
|
||||
@MongoVersion(asOf = "3.2")
|
||||
public void sliceShouldBeAppliedCorrectly() {
|
||||
void sliceShouldBeAppliedCorrectly() {
|
||||
|
||||
createUserWithLikesDocuments();
|
||||
|
||||
@@ -1667,7 +1667,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1491
|
||||
public void filterShouldBeAppliedCorrectly() {
|
||||
void filterShouldBeAppliedCorrectly() {
|
||||
|
||||
Item item43 = Item.builder().itemId("43").quantity(2).price(2L).build();
|
||||
Item item2 = Item.builder().itemId("2").quantity(1).price(240L).build();
|
||||
@@ -1697,7 +1697,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1538
|
||||
public void letShouldBeAppliedCorrectly() {
|
||||
void letShouldBeAppliedCorrectly() {
|
||||
|
||||
Sales2 sales1 = Sales2.builder().id("1").price(10).tax(0.5F).applyDiscount(true).build();
|
||||
Sales2 sales2 = Sales2.builder().id("2").price(10).tax(0.25F).applyDiscount(false).build();
|
||||
@@ -1721,7 +1721,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1551, DATAMONGO-2264
|
||||
public void graphLookupShouldBeAppliedCorrectly() {
|
||||
void graphLookupShouldBeAppliedCorrectly() {
|
||||
|
||||
Employee em1 = Employee.builder().id(1).name("Dev").build();
|
||||
Employee em2 = Employee.builder().id(2).name("Eliot").reportsTo("Dev").build();
|
||||
@@ -1753,7 +1753,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1552
|
||||
public void bucketShouldCollectDocumentsIntoABucket() {
|
||||
void bucketShouldCollectDocumentsIntoABucket() {
|
||||
|
||||
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
|
||||
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
|
||||
@@ -1787,7 +1787,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1552, DATAMONGO-2437
|
||||
public void bucketAutoShouldCollectDocumentsIntoABucket() {
|
||||
void bucketAutoShouldCollectDocumentsIntoABucket() {
|
||||
|
||||
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
|
||||
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
|
||||
@@ -1820,7 +1820,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1552
|
||||
public void facetShouldCreateFacets() {
|
||||
void facetShouldCreateFacets() {
|
||||
|
||||
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
|
||||
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
|
||||
@@ -1863,7 +1863,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1986
|
||||
public void runMatchOperationCriteriaThroughQueryMapperForTypedAggregation() {
|
||||
void runMatchOperationCriteriaThroughQueryMapperForTypedAggregation() {
|
||||
|
||||
mongoTemplate.insertAll(TestEntities.geolocation().newYork());
|
||||
|
||||
@@ -1878,7 +1878,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1986
|
||||
public void runMatchOperationCriteriaThroughQueryMapperForUntypedAggregation() {
|
||||
void runMatchOperationCriteriaThroughQueryMapperForUntypedAggregation() {
|
||||
|
||||
mongoTemplate.insertAll(TestEntities.geolocation().newYork());
|
||||
|
||||
@@ -1893,7 +1893,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2437
|
||||
public void shouldReadComplexIdValueCorrectly() {
|
||||
void shouldReadComplexIdValueCorrectly() {
|
||||
|
||||
WithComplexId source = new WithComplexId();
|
||||
source.id = new ComplexId();
|
||||
@@ -1908,7 +1908,7 @@ public class AggregationTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2536
|
||||
public void skipOutputDoesNotReadBackAggregationResults() {
|
||||
void skipOutputDoesNotReadBackAggregationResults() {
|
||||
|
||||
createTagDocuments();
|
||||
|
||||
@@ -2021,7 +2021,7 @@ public class AggregationTests {
|
||||
String pDch;
|
||||
@org.springframework.data.mongodb.core.mapping.Field("alias") int up;
|
||||
|
||||
public PD(String pDch, int up) {
|
||||
PD(String pDch, int up) {
|
||||
this.pDch = pDch;
|
||||
this.up = up;
|
||||
}
|
||||
@@ -2036,7 +2036,7 @@ public class AggregationTests {
|
||||
|
||||
public DATAMONGO788() {}
|
||||
|
||||
public DATAMONGO788(int x, int y) {
|
||||
DATAMONGO788(int x, int y) {
|
||||
this.x = x;
|
||||
this.xField = x;
|
||||
this.y = y;
|
||||
@@ -2052,7 +2052,7 @@ public class AggregationTests {
|
||||
|
||||
public User() {}
|
||||
|
||||
public User(String id, PushMessage... msgs) {
|
||||
User(String id, PushMessage... msgs) {
|
||||
this.id = id;
|
||||
this.msgs = Arrays.asList(msgs);
|
||||
}
|
||||
@@ -2067,7 +2067,7 @@ public class AggregationTests {
|
||||
|
||||
public PushMessage() {}
|
||||
|
||||
public PushMessage(String id, String content, Date createDate) {
|
||||
PushMessage(String id, String content, Date createDate) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
this.createDate = createDate;
|
||||
@@ -2082,7 +2082,7 @@ public class AggregationTests {
|
||||
private String lastName;
|
||||
private Descriptors descriptors;
|
||||
|
||||
public CarPerson(String firstname, String lastname, Entry... entries) {
|
||||
CarPerson(String firstname, String lastname, Entry... entries) {
|
||||
this.firstName = firstname;
|
||||
this.lastName = lastname;
|
||||
|
||||
@@ -2102,7 +2102,7 @@ public class AggregationTests {
|
||||
|
||||
private List<Entry> entries = new ArrayList<AggregationTests.CarDescriptor.Entry>();
|
||||
|
||||
public CarDescriptor(Entry... entries) {
|
||||
CarDescriptor(Entry... entries) {
|
||||
|
||||
for (Entry entry : entries) {
|
||||
this.entries.add(entry);
|
||||
@@ -2118,7 +2118,7 @@ public class AggregationTests {
|
||||
|
||||
public Entry() {}
|
||||
|
||||
public Entry(String make, String model, int year) {
|
||||
Entry(String make, String model, int year) {
|
||||
this.make = make;
|
||||
this.model = model;
|
||||
this.year = year;
|
||||
@@ -2134,7 +2134,7 @@ public class AggregationTests {
|
||||
|
||||
public Reservation() {}
|
||||
|
||||
public Reservation(String hotelCode, String confirmationNumber, int timestamp) {
|
||||
Reservation(String hotelCode, String confirmationNumber, int timestamp) {
|
||||
this.hotelCode = hotelCode;
|
||||
this.confirmationNumber = confirmationNumber;
|
||||
this.timestamp = timestamp;
|
||||
@@ -2145,7 +2145,7 @@ public class AggregationTests {
|
||||
|
||||
Date dateValue;
|
||||
|
||||
public ObjectWithDate(Date dateValue) {
|
||||
ObjectWithDate(Date dateValue) {
|
||||
this.dateValue = dateValue;
|
||||
}
|
||||
}
|
||||
@@ -2161,14 +2161,14 @@ public class AggregationTests {
|
||||
|
||||
public InventoryItem() {}
|
||||
|
||||
public InventoryItem(int id, String item, int qty) {
|
||||
InventoryItem(int id, String item, int qty) {
|
||||
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
this.qty = qty;
|
||||
}
|
||||
|
||||
public InventoryItem(int id, String item, String description, int qty) {
|
||||
InventoryItem(int id, String item, String description, int qty) {
|
||||
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
|
||||
@@ -181,5 +181,4 @@ public class ReactiveAggregationTests {
|
||||
reactiveMongoTemplate.aggregate(agg, Document.class).as(StepVerifier::create).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user