Mongo-Hadoop 待我称王封你为后i 2022-08-06 20:58 123阅读 0赞 **下载** [https://github.com/mongodb/mongo-hadoop/releases][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); ![231728503497990.jpg][] **注意**: import的不要是 com.mongodb.hadoop.**mapred**.MongoInputFormat;,而是 import com.mongodb.hadoop.MongoOutputFormat; import com.mongodb.hadoop.MongoInputFormat; import com.mongodb.hadoop.util.MongoConfigUtil; BasicBSONObject output = new BasicBSONObject (); output . put ( "count" , count ); output . put ( "avg" , avg ); output . put ( "sum" , sum ); pContext . write ( pKey , new BSONWritable ( output )); [https_github.com_mongodb_mongo-hadoop_releases]: https://github.com/mongodb/mongo-hadoop/releases [231728503497990.jpg]: /images/20220805/561663b162c04bbfb33bdc8e55621d3d.png
还没有评论,来说两句吧...