Support Questions
Find answers, ask questions, and share your expertise

load data from mongoDB to spark dataframe

Explorer

i am trying to load data from mongodb to spark as a dataframe , here is what i did but i got an error you will find below any help will be appreciated

import org.apache.spark.sql.SparkSession
import com.mongodb.spark.sql._
import com.mongodb.spark._
import org.bson.Document
import com.mongodb.spark.config._
object MongoDB extends App{
try
{val sparkSession =SparkSession.builder().master("local").getOrCreate()
def makeMongoURI(uri:String,database:String,collection:String)=(s"${uri}/${database}.${collection}")
val mongoURI ="mongodb://127.0.0.1:27017"
val Conf= makeMongoURI(mongoURI,"io","thing")
val readConfigintegra:ReadConfig=ReadConfig(Map("uri"->Conf)) 
val df3 = sparkSession.sqlContext.loadFromMongoDB(ReadConfig(Map("uri"->"mongodb://127.0.0.1:27017/io.thing"))) 
df3.printSchema()}
catch{
case t:Throwable=> t.printStackTrace()// TODO: handle error 
  println(t.getMessage)
      }
    }
    

14676-captureerror.png

  
0 REPLIES 0