Spark connects to MongoDB

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.