From 3f7b0f1eb660a33d29a1ddc8a06e8613d5dce442 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 20 Jan 2015 18:12:18 +0100 Subject: [PATCH] DATAMONGO-1082 - Improved documentation of alias usage in aggregation framework. Added missing JavaDoc and added short note to the reference documentation. Original pull request: #268. --- .../data/mongodb/core/aggregation/Fields.java | 30 +++++++++++++++---- src/main/asciidoc/reference/mongodb.adoc | 3 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java index 3c7160a77..70cd2070a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,6 +84,15 @@ public final class Fields implements Iterable { return new AggregationField(name); } + /** + * Creates a {@link Field} with the given {@code name} and {@code target}. + *

+ * The {@code target} is the name of the backing document field that will be aliased with {@code name}. + * + * @param name + * @param target must not be {@literal null} or empty + * @return + */ public static Field field(String name, String target) { Assert.hasText(target, "Target must not be null or empty!"); return new AggregationField(name, target); @@ -187,15 +196,24 @@ public final class Fields implements Iterable { private final String target; /** - * Creates an aggregation field with the given name. As no target is set explicitly, the name will be used as target - * as well. + * Creates an aggregation field with the given {@code name}. * - * @param key + * @see AggregationField#AggregationField(String, String). + * @param name must not be {@literal null} or empty */ - public AggregationField(String key) { - this(key, null); + public AggregationField(String name) { + this(name, null); } + /** + * Creates an aggregation field with the given {@code name} and {@code target}. + *

+ * The {@code name} serves as an alias for the actual backing document field denoted by {@code target}. If no target + * is set explicitly, the name will be used as target. + * + * @param name must not be {@literal null} or empty + * @param target + */ public AggregationField(String name, String target) { String nameToSet = cleanUp(name); diff --git a/src/main/asciidoc/reference/mongodb.adoc b/src/main/asciidoc/reference/mongodb.adoc index 9f655cdef..c462eb256 100644 --- a/src/main/asciidoc/reference/mongodb.adoc +++ b/src/main/asciidoc/reference/mongodb.adoc @@ -1538,7 +1538,8 @@ Note that the aggregation operations not listed here are currently not supported [[mongo.aggregation.projection]] === Projection Expressions -Projection expressions are used to define the fields that are the outcome of a particular aggregation step. Projection expressions can be defined via the `project` method of the `Aggregate` class. +Projection expressions are used to define the fields that are the outcome of a particular aggregation step. Projection expressions can be defined via the `project` method of the `Aggregate` class either by passing a list of `String`s or an aggregation framework `Fields` object. The projection can be extended with additional fields through a fluent API via the `and(String)` method and aliased via the `as(String)` method. +Note that one can also define fields with aliases via the static factory method `Fields.field` of the aggregation framework that can then be used to construct a new `Fields` instance. .Projection expression examples ====