简体   繁体   中英

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM