Spark与MongoDB连接

系统:

Ubuntu_18.01

Spark_2.3.1

Scala_2.12.6

MongoDB_3.6.3

参考MongoDB官方网址:https://github.com/mongodb/mongo-spark

$ git clone https://github.com/mongodb/mongo-spark.git
$ cd mongo-spark
$ ./sbt check  (这个地方费点时间,耐心等待)
$ ./sbt +publish-signed
$ ./sbt +spPublish

 

本文使用mongodb官方的MongoDB Connector for Apache Spark,先下载MongoDB Connector for Apache Spark 。

MongoDB Connector for Apache Spark的使用方法非常简单,到spark的安装的bin目录下执行下面语句:

cd /usr/local/spark/bin

按照官方文档启动Spark Connector Scala Guide

./spark-shell  --conf "spark.mongodb.input.uri=mongodb://localhost:27017/test.test?authSource=admin" --conf "spark.mongodb.output.uri=mongodb://localhost:27017/test.test?authSource=admin" --packages org.mongodb.spark:mongo-spark-connector_2.12:2.4.0

 

参考:http://michaeljian.top/2017/12/15/Apache-Spark%E8%BF%9E%E6%8E%A5MongoDB/



你只管努力,其他的交给天意~
原文地址:https://www.cnblogs.com/genghenggao/p/10308887.html