1.SBT Content:
Name: = "Data_ana"
Version: = "1.0"
scalaversion: = "2.11.8"
librarydependencies ++= Seq (
"Org.apache.spark" percent "Spark-core"% "2.2.0",
"Org.apache.spark" percent "spark-sql"% "2.2.0",
"Org.apache.hadoop"% "hadoop-client"% "2.7.3",
"Org.mongodb"% "mongo-java-driver"% "3.4.2",
"Org.mongodb.mongo-hadoop"% "Mongo-hadoop-core"% "2.0.2",
"Org.mongodb.spark" percent "mongo-spark-connector"% "2.2.0"
)
2. Simple test Code
Import Com.mongodb.spark._
Import Org.apache.spark.sql.SparkSession
Object Mongdb_test {
def main (args:array[string]): Unit = {
val spark = Sparksession
. Builder ()
. Master ("local")
. AppName ("lining")
. config ("Spark.mongodb.input.uri", "Mongodb://name:[email protected]:27017/database_name.table_name")
. config ("Spark.mongodb.output.uri", "Mongodb://name:[email protected]:27017/database_name.table_name")
. Getorcreate ()
Val Lines=mongospark.load (Spark)
Lines.printschema ()
Lines.show ()
}
}
3. RELATED LINKS
https://docs.mongodb.com/spark-connector/current/scala/datasets-and-sql/
Http://spark.apache.org/docs/2.1.0/sql-programming-guide.html
Http://www.thebigdata.cn/MongoDB/31116.html
Spark connects to MongoDB