Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB: Perform mapreduce and filter with java driver 3.0.x

I'm working in a java small project and mongoDB with java driver 3.0.1. Need perform a MapReduce algorithm and before map function, execute one query to have less data and increment the performance.

I've seen api driver and exist the class MongoCollection with method mapReduce but only with map and reduce function as parameter. it doesn't have any query param.

dbConnection.getCollection("test").mapReduce(mapFunction, reduceFunction)

In old API, has MapReduceCommand for do this

MapReduceCommand cmd = new MapReduceCommand("test", map, reduce, null, MapReduceCommand.OutputType.INLINE, query)

Any suggestions?

Thanks all!

like image 564
limkin Avatar asked Feb 11 '23 01:02

limkin


1 Answers

The mapReduce method on MongoCollection returns an instance of a MapReduceIterable, which has a filter method for the query filter to apply to the collection before executing the map phase. It looks like this:

dbConnection.getCollection("test").mapReduce(mapFunction, reduceFunction)
                                  .filter(queryFilter)
like image 116
jyemin Avatar answered Feb 13 '23 03:02

jyemin