/** * Allows you to run map-reduce aggregation operations over a collection. * * @param map a JavaScript function that associates or "maps" a value with a key and emits the key and value pair. * @param reduce a JavaScript function that "reduces" to a single object all the values associated with a particular key. * @param outputTarget specifies the location of the result of the map-reduce operation. * @param query specifies the selection criteria using query operators for determining the documents input to the map function. * @return a MapReduceOutput which contains the results of this map reduce operation * @mongodb.driver.manual core/map-reduce/ Map-Reduce */ public MapReduceOutput mapReduce(final String map, final String reduce, final String outputTarget, final DBObject query) { MapReduceCommand command = new MapReduceCommand(this, map, reduce, outputTarget, MapReduceCommand.OutputType.REDUCE, query); return mapReduce(command); }
/** * Allows you to run map-reduce aggregation operations over a collection and saves to a named collection. * * @param map a JavaScript function that associates or "maps" a value with a key and emits the key and value pair. * @param reduce a JavaScript function that "reduces" to a single object all the values associated with a particular key. * @param outputTarget specifies the location of the result of the map-reduce operation. * @param outputType specifies the type of job output * @param query specifies the selection criteria using query operators for determining the documents input to the map function. * @return a MapReduceOutput which contains the results of this map reduce operation * @mongodb.driver.manual core/map-reduce/ Map-Reduce */ public MapReduceOutput mapReduce(final String map, final String reduce, final String outputTarget, final MapReduceCommand.OutputType outputType, final DBObject query) { MapReduceCommand command = new MapReduceCommand(this, map, reduce, outputTarget, outputType, query); return mapReduce(command); }
/** * Allows you to run map-reduce aggregation operations over a collection and saves to a named collection. * * @param map a JavaScript function that associates or "maps" a value with a key and emits the key and value pair. * @param reduce a JavaScript function that "reduces" to a single object all the values associated with a particular key. * @param outputTarget specifies the location of the result of the map-reduce operation. * @param outputType specifies the type of job output * @param query specifies the selection criteria using query operators for determining the documents input to the map * function. * @param readPreference the read preference specifying where to run the query. Only applied for Inline output type * @return a MapReduceOutput which contains the results of this map reduce operation * @mongodb.driver.manual core/map-reduce/ Map-Reduce */ public MapReduceOutput mapReduce(final String map, final String reduce, final String outputTarget, final MapReduceCommand.OutputType outputType, final DBObject query, final ReadPreference readPreference) { MapReduceCommand command = new MapReduceCommand(this, map, reduce, outputTarget, outputType, query); command.setReadPreference(readPreference); return mapReduce(command); }
@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; }
MapreduceResults<T> results = new MapreduceResults<T>(dbColl.mapReduce(baseCommand));
final MapReduceOutput output = mongoDb.getCollection(command.getInput()).mapReduce(command);
/** * performs a map reduce operation * * @param command object representing the parameters * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(DBObject command) throws MongoException { return dbCollection.mapReduce(command); }
/** * performs a map reduce operation * * @param command object representing the parameters * @return The results * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(MapReduceCommand command) throws MongoException { return dbCollection.mapReduce(command); }
/** * performs a map reduce operation * * @param command object representing the parameters * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(DBObject command) throws MongoException { return dbCollection.mapReduce(command); }
/** * performs a map reduce operation * * @param command object representing the parameters * @return The results * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(MapReduceCommand command) throws MongoException { return dbCollection.mapReduce(command); }
/** * performs a map reduce operation * * @param command * object representing the parameters * @return The results * @throws MongoException * If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(MapReduceCommand command) throws MongoException { return dbCollection.mapReduce(command); }
public Iterable<DBObject> mapReduce(String map, String reduce) { MapReduceOutput output = getCollection().mapReduce(map, reduce, null, MapReduceCommand.OutputType.INLINE, null); return output.results(); }
public Iterable<DBObject> mapReduce(MapReduceCommand cmd) { MapReduceOutput output = getCollection().mapReduce(cmd); return output.results(); }
private Iterable<DBObject> mapReduce(String map, String reduce, DBObject query) { MapReduceOutput output = getCollection().mapReduce(map, reduce, null, MapReduceCommand.OutputType.INLINE, query); return output.results(); }
public Map<String, Long> cloud(String field) { field = MorphiaPlugin.mongoColName(c_, field); String map = String.format("function() {if (!this.%1$s) return; for (index in this.%1$s) emit(this.%1$s[index], 1);}", field); String reduce = "function(previous, current) {var count = 0; for (index in current) count += current[index]; return count;}"; MapReduceCommand cmd = new MapReduceCommand(col(), map, reduce, null, MapReduceCommand.OutputType.INLINE, q_.getQueryObject()); MapReduceOutput out = col().mapReduce(cmd); Map<String, Long> m = new HashMap<String, Long>(); for (Iterator<DBObject> itr = out.results().iterator(); itr.hasNext(); ) { DBObject dbo = itr.next(); m.put((String) dbo.get("_id"), ((Double) dbo.get("value")).longValue()); } return m; }
/** * Performs a map reduce operation * * @param command The command to execute * @return The output * @throws MongoException If an error occurred */ public <S, L> MapReduceOutput<S, L> mapReduce(MapReduce.MapReduceCommand<S, L> command) throws MongoException { return new MapReduceOutput<S, L>(this, dbCollection.mapReduce(command.build(this)), command.getResultType(), command.getKeyType()); }
/** * Performs a map reduce operation * * @param command The command to execute * @return The output * @throws MongoException If an error occurred */ public <S, L> MapReduceOutput<S, L> mapReduce(MapReduce.MapReduceCommand<S, L> command) throws MongoException { return new MapReduceOutput<S, L>(this, dbCollection.mapReduce(command.build(this)), command.getResultType(), command.getKeyType()); }
@Override public Bounds bbox(DBCollection dbcol, MongoDataset data) { MapReduceCommand mr = new MapReduceCommand( dbcol, bboxMap, bboxReduce, null, OutputType.INLINE, new BasicDBObject()); BasicDBList list = (BasicDBList) dbcol.mapReduce(mr).getCommandResult().get("results"); DBObject bbox = (DBObject) ((DBObject) list.get(0)).get("value"); return new Bounds((Double)bbox.get("x1"), (Double)bbox.get("x2"), (Double)bbox.get("y1"), (Double)bbox.get("y2")); }
public Iterable<DBObject> mapReduce(String collectionName, String map, String reduce, DBObject query) throws OperatorException { MapReduceOutput _output = getCollection(collectionName).mapReduce(map, reduce, null, OutputType.INLINE, query); CommandResult _result = _output.getCommandResult(); if (!_result.ok()) { throw new OperatorException(_result.getErrorMessage()); } return _output.results(); }
@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; }