Browse Source

DATAMONGO-586 - Adjusted examples in reference documentation.

Changed examples in reference documentation to reflect the new DSL style.
pull/58/merge
Thomas Darimont 13 years ago committed by Oliver Gierke
parent
commit
ad44db386b
  1. 1
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java
  2. 36
      src/docbkx/reference/mongodb.xml

1
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java

@ -297,7 +297,6 @@ public class AggregationTests {
.first("city").as("smallestCity") // .first("city").as("smallestCity") //
.first("pop").as("smallestPop"), // .first("pop").as("smallestPop"), //
project() // project() //
// .and(previousOperation()).exclude() //
.and("state").previousOperation() // .and("state").previousOperation() //
.and("biggestCity").nested(bind("name", "biggestCity").and("population", "biggestPop")) // .and("biggestCity").nested(bind("name", "biggestCity").and("population", "biggestPop")) //
.and("smallestCity").nested(bind("name", "smallestCity").and("population", "smallestPop")), // .and("smallestCity").nested(bind("name", "smallestCity").and("population", "smallestPop")), //

36
src/docbkx/reference/mongodb.xml

@ -2294,10 +2294,17 @@ List<OutputType> mappedResult = results.getMappedResults();
<row> <row>
<entry>Group Aggregation Operators</entry> <entry>Group Aggregation Operators</entry>
<entry>add_to_set, first, last, max, min, avg, push, sum, <entry>addToSet, first, last, max, min, avg, push, sum,
(*count)</entry> (*count)</entry>
</row> </row>
<row>
<entry>Arithmetic Aggregation Operators</entry>
<entry>add (*via plus), subtract (*via minus), multiply, divide,
mod</entry>
</row>
<row> <row>
<entry>Comparison Aggregation Operators</entry> <entry>Comparison Aggregation Operators</entry>
@ -2308,7 +2315,8 @@ List&lt;OutputType&gt; mappedResult = results.getMappedResults();
</table> </table>
<para>Note that the aggregation operations not listed here are currently <para>Note that the aggregation operations not listed here are currently
not supported by Spring Data MongoDB. </para> not supported by Spring Data MongoDB. Comparison aggregation operators
are expressed as <classname>Criteria</classname> expressions.</para>
<para>*) The operation is mapped or added by Spring Data MongoDB.</para> <para>*) The operation is mapped or added by Spring Data MongoDB.</para>
</section> </section>
@ -2325,8 +2333,8 @@ List&lt;OutputType&gt; mappedResult = results.getMappedResults();
<para>In order to do this we first create a new aggregation via the <para>In order to do this we first create a new aggregation via the
<methodname>newAggregation</methodname> static factory method to which <methodname>newAggregation</methodname> static factory method to which
we pass a list of aggregation operations. These aggregate operations we pass a list of aggregation operations. These aggregate operations
form the aggregation pipeline of our <classname>Aggregation</classname>. form the aggregation pipeline of our
</para> <classname>Aggregation</classname>.</para>
<para>As a first step we select the <code>"tags"</code> field (which is <para>As a first step we select the <code>"tags"</code> field (which is
an array of strings) from the input collection with the an array of strings) from the input collection with the
@ -2343,8 +2351,9 @@ List&lt;OutputType&gt; mappedResult = results.getMappedResults();
<code>"n"</code>.</para> <code>"n"</code>.</para>
<para>As a forth step we select the field <code>"n"</code> and create an <para>As a forth step we select the field <code>"n"</code> and create an
alias for the id-field generated from the previous group operation with alias for the id-field generated from the previous group operation
the name <code>"tag"</code>. </para> (hence the call to <code>previousOperation()</code>) with the name
<code>"tag"</code>.</para>
<para>Finally as the fifth step we sort the resulting list of tags by <para>Finally as the fifth step we sort the resulting list of tags by
their occurence count in descending order via the their occurence count in descending order via the
@ -2366,7 +2375,7 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
Aggregation agg = newAggregation( Aggregation agg = newAggregation(
project("tags"), project("tags"),
unwind("tags"), unwind("tags"),
group("tags").and("n").count(), group("tags").count().as("n"),
project("n").and("tag").previousOperation(), project("n").and("tag").previousOperation(),
sort(DESC, "n") sort(DESC, "n")
); );
@ -2462,15 +2471,14 @@ class ZipInfoStats {
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
TypedAggregation&lt;ZipInfo&gt; aggregation = newAggregation(ZipInfo.class, TypedAggregation&lt;ZipInfo&gt; aggregation = newAggregation(ZipInfo.class,
group("state", "city").and("pop").sum("population"), group("state", "city").sum("population").as("pop"),
sort(ASC, "pop", "state", "city"), sort(ASC, "pop", "state", "city"),
group("state") group("state")
.and("biggestCity").last("city") .last("city").as("biggestCity")
.and("biggestPop").last("pop") .last("pop").as("biggestPop")
.and("smallestCity").first("city") .first("city").as("smallestCity")
.and("smallestPop").first("pop"), .first("pop").as("smallestPop"),
project() project()
.and(previousOperation()).exclude()
.and("state").previousOperation() .and("state").previousOperation()
.and("biggestCity").nested(bind("name", "biggestCity").and("population", "biggestPop")) .and("biggestCity").nested(bind("name", "biggestCity").and("population", "biggestPop"))
.and("smallestCity").nested(bind("name", "smallestCity").and("population", "smallestPop")), .and("smallestCity").nested(bind("name", "smallestCity").and("population", "smallestPop")),
@ -2522,7 +2530,7 @@ ZipInfoStats firstZipInfoStats = result.getMappedResults().get(0);
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
TypedAggregation&lt;ZipInfo&gt; agg = newAggregation(ZipInfo.class, TypedAggregation&lt;ZipInfo&gt; agg = newAggregation(ZipInfo.class,
group("state").and("totalPop").sum("population"), group("state").sum("population").as("totalPop"),
sort(ASC, previousOperation(), "totalPop"), sort(ASC, previousOperation(), "totalPop"),
match(where("totalPop").gte(10 * 1000 * 1000)) match(where("totalPop").gte(10 * 1000 * 1000))
); );

Loading…
Cancel
Save