@Override public <T> MapreduceResults<T> mapReduce(final MapReduceOptions<T> options) { DBCollection collection = options.getQuery().getCollection(); final EntityCache cache = createCache(); MapreduceResults<T> results = new MapreduceResults<T>(collection.mapReduce(options.toCommand(getMapper()))); results.setOutputType(options.getOutputType()); if (OutputType.INLINE.equals(options.getOutputType())) { results.setInlineRequiredOptions(this, options.getResultType(), getMapper(), cache); } else { results.setQuery(newQuery(options.getResultType(), getDB().getCollection(results.getOutputCollectionName()))); } return results; }
@SuppressWarnings("deprecation") MapReduceCommand toCommand(final Mapper mapper) { if (query.getOffset() != 0 || query.getFieldsObject() != null) { throw new QueryException("mapReduce does not allow the offset/retrievedFields query "); } final DBCollection dbColl = inputCollection != null ? getQuery().getCollection().getDB().getCollection(inputCollection) : query.getCollection(); final String target = outputCollection != null ? outputCollection : mapper.getMappedClass(resultType).getCollectionName(); final MapReduceCommand command = new MapReduceCommand(dbColl, map, reduce, target, outputType, query.getQueryObject()); command.setBypassDocumentValidation(bypassDocumentValidation); command.setCollation(collation); command.setFinalize(finalize); command.setJsMode(jsMode); command.setLimit(limit); command.setMaxTime(maxTimeMS, TimeUnit.MILLISECONDS); command.setOutputDB(outputDB); command.setReadPreference(readPreference); command.setScope(scope); command.setSort(query.getSortObject()); command.setVerbose(verbose); return command; } }