Skip to content

Commit 3f7b0f1

Browse files
Thomas Darimontodrotbohm
Thomas Darimont
authored andcommitted
DATAMONGO-1082 - Improved documentation of alias usage in aggregation framework.
Added missing JavaDoc and added short note to the reference documentation. Original pull request: spring-projects#268.
1 parent 4055365 commit 3f7b0f1

File tree

2 files changed

+26
-7
lines changed
  • spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation
  • src/main/asciidoc/reference

2 files changed

+26
-7
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,6 +84,15 @@ public static Field field(String name) {
8484
return new AggregationField(name);
8585
}
8686

87+
/**
88+
* Creates a {@link Field} with the given {@code name} and {@code target}.
89+
* <p>
90+
* The {@code target} is the name of the backing document field that will be aliased with {@code name}.
91+
*
92+
* @param name
93+
* @param target must not be {@literal null} or empty
94+
* @return
95+
*/
8796
public static Field field(String name, String target) {
8897
Assert.hasText(target, "Target must not be null or empty!");
8998
return new AggregationField(name, target);
@@ -187,15 +196,24 @@ static class AggregationField implements Field {
187196
private final String target;
188197

189198
/**
190-
* Creates an aggregation field with the given name. As no target is set explicitly, the name will be used as target
191-
* as well.
199+
* Creates an aggregation field with the given {@code name}.
192200
*
193-
* @param key
201+
* @see AggregationField#AggregationField(String, String).
202+
* @param name must not be {@literal null} or empty
194203
*/
195-
public AggregationField(String key) {
196-
this(key, null);
204+
public AggregationField(String name) {
205+
this(name, null);
197206
}
198207

208+
/**
209+
* Creates an aggregation field with the given {@code name} and {@code target}.
210+
* <p>
211+
* The {@code name} serves as an alias for the actual backing document field denoted by {@code target}. If no target
212+
* is set explicitly, the name will be used as target.
213+
*
214+
* @param name must not be {@literal null} or empty
215+
* @param target
216+
*/
199217
public AggregationField(String name, String target) {
200218

201219
String nameToSet = cleanUp(name);

src/main/asciidoc/reference/mongodb.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,8 @@ Note that the aggregation operations not listed here are currently not supported
15381538
[[mongo.aggregation.projection]]
15391539
=== Projection Expressions
15401540

1541-
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.
1541+
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.
1542+
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.
15421543

15431544
.Projection expression examples
15441545
====

0 commit comments

Comments
 (0)