Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

load data from mongoDB to spark dataframe

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

  
Don't have an account?
Coming from Hortonworks? Activate your account here