List of usage examples for org.springframework.data.mongodb.core.mapreduce MapReduceResults getCounts
public MapReduceCounts getCounts()
From source file:io.github.microcks.repository.DailyStatisticRepositoryImpl.java
@Override public DailyStatistic aggregateDailyStatistics(String day) { // Build a query to pre-select the statistics that will be aggregated. Query query = new Query(Criteria.where("day").is(day)); // Execute a MapReduce command. MapReduceResults<WrappedDailyStatistic> results = template.mapReduce(query, "dailyStatistic", "classpath:mapDailyStatisticForADay.js", "classpath:reduceDailyStatisticForADay.js", WrappedDailyStatistic.class); // Output some debug messages. if (log.isDebugEnabled()) { log.debug("aggregateDailyStatistics mapReduce for day " + day); log.debug("aggregateDailyStatistics mapReduce result counts: " + results.getCounts()); for (WrappedDailyStatistic wdt : results) { log.debug("aggregateDailyStatistics mapReduce result value: " + wdt.getValue()); }// w ww .j a v a 2 s. c o m } // We've got a result if we've got an output. if (results.getCounts().getOutputCount() > 0) { return results.iterator().next().getValue(); } // Build and return an empty object otherwise? DailyStatistic statistic = new DailyStatistic(); statistic.setDay(day); statistic.setDailyCount(0); return statistic; }