资 源 简 介
private static MongoTemplate mongoTemplate;
static {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
mongoTemplate = (MongoTemplate) context.getBean("mongoTemplate");
}
public static void main(String[] args) throws Exception{
//initData();
//test1Mapreduce();
//test1Aggregation();
//testMapreduce2();
//testMapReduce3();
testMapreduce4();
}
/**
* 统计出用户浏览过的页面地址
*/
private static void testMapreduce4() {
MapReduceOptions options = MapReduceOptions.options();
String outCollName = "urls";
options.outputCollection(outCollName);
options.outputTypeReduce();
mongoTemplate.mapReduce(new Query(), "userBrowseHistory",
"classpath:historyMap4.js", "classpath:historyReduce4.js", options, DayCount.class);
}
/**
* 统计出一段时间内用户平均每天访问的次数
*/
private static void testMapReduce3() {
//为什么不能在reduce中求平均数:因为当某些唯一key的数据只有一条时,不能进入reduce,所以这个时候算平均数
//的话