13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

please define productname in your docbook file!public class XObject {private float x;private float count;public float getX() {return x;}public void setX(float x) {this.x = x;}public float getCount() {return count;}public void setCount(float count) {this.count = count;}}@Overridepublic String toString() {return "XObject [x=" + x + " count = " + count + "]";}You can also obtain tha raw result as a DbObject by calling the method getRawResults on theGroupByResults class.There is an additional method overload of the group method on MongoOperations which lets youspecify a Criteria object for selecting a subset of the rows. An example which uses a Criteriaobject, with some syntax sugar using static imports, as well as referencing a key-function and reducefunction javascript files via a <strong>Spring</strong> Resource string is shown below.import static org.springframework.data.mongodb.core.mapreduce.GroupBy.keyFunction;import static org.springframework.data.mongodb.core.query.Criteria.where;GroupByResults results = mongoTemplate.group(where("x").gt(0),"group_test_collection",keyFunction("classpath:keyFunction.js").initialDocument("{ count:0 }").reduceFunction("classpath:groupReduce.js"), XObject.class);5.9 Aggregation Framework Support<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> provides support for the Aggregation Framework introduced to <strong>MongoDB</strong> inversion 2.2.The <strong>MongoDB</strong> Documentation describes the Aggregation Framework as follows:“The <strong>MongoDB</strong>aggregation framework provides a means to calculate aggregated values without having to use mapreduce.While map-reduce is powerful, it is often more difficult than necessary for many simpleaggregation tasks, such as totaling or averaging field values.”For further information see the full reference documentation of the aggregation framework and otherdata aggregation tools for <strong>MongoDB</strong>.1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!