List of usage examples for com.mongodb MapReduceOutput results
@SuppressWarnings("unchecked") public Iterable<DBObject> results()
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
License:Apache License
public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass) { String mapFunc = replaceWithResourceIfNecessary(mapFunction); String reduceFunc = replaceWithResourceIfNecessary(reduceFunction); DBCollection inputCollection = getCollection(inputCollectionName); MapReduceCommand command = new MapReduceCommand(inputCollection, mapFunc, reduceFunc, mapReduceOptions.getOutputCollection(), mapReduceOptions.getOutputType(), query == null || query.getQueryObject() == null ? null : queryMapper.getMappedObject(query.getQueryObject(), null)); copyMapReduceOptionsToCommand(query, mapReduceOptions, command); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing MapReduce on collection [{}], mapFunction [{}], reduceFunction [{}]", command.getInput(), mapFunc, reduceFunc); }//from w w w.j a v a 2 s . com MapReduceOutput mapReduceOutput = inputCollection.mapReduce(command); if (LOGGER.isDebugEnabled()) { LOGGER.debug("MapReduce command result = [{}]", serializeToJsonSafely(mapReduceOutput.results())); } List<T> mappedResults = new ArrayList<T>(); DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass, inputCollectionName); for (DBObject dbObject : mapReduceOutput.results()) { mappedResults.add(callback.doWith(dbObject)); } return new MapReduceResults<T>(mappedResults, mapReduceOutput); }