下載
https://github.com/mongodb/mongo-hadoop/releases
解壓到/home/kevin/hadoop/hadoop/share/mongo-hadoop-2.2-1.2.0
(其實是任意,真正分佈式的時候要注意這個jar包的問題)
Mapreduce結果輸出到MongDB
要修改的代碼(input類似 ps:extends Mapper<Object,BSONObject, IntWritable,DoubleWritable>)
//FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); MongoConfigUtil.setOutputURI(conf, "mongodb://localhost:27017/test.out"); job.setOutputFormatClass(MongoOutputFormat.class);
注意:
import的不要是 com.mongodb.hadoop.mapred.MongoInputFormat;,而是
import com.mongodb.hadoop.MongoOutputFormat;
import com.mongodb.hadoop.MongoInputFormat;
import com.mongodb.hadoop.util.MongoConfigUtil;