I am having Mongodb Cluser (3.2.5) on azure cloud. Usig casbah 3.1 ( casbah-commons_2.11-3.1.0-rc0.jar , casbah-core_2.11-3.1.0-rc0.jar ,casbah-query_2.11-3.1.0-rc0.jar)
I have the spark scala code that read events from EventHub and want to write the same to Mongodb. The code snipet of iterating through RDD and write to mongodb is as below.. I am able to write a normal string to mongodb outside of RDD but the same thing do not work when in RDD and throw compiler error as below.
myvents.foreachRDD { rdd =>
rdd.foreachPartition { iterator =>
val mongoClient = MongoClient(uri)
val sensordatacollection = mongoClient("iotdb")("sensordata")
iterator.foreach { element =>
val oneEvent = element.split(",")
val eventObj = MongoDBObject
("regionCode" -> "sdsafsd",
"vehicleID" -> "sdsafsd",
"LocationLg" -> "sdsafsd",
"LocationLt" -> "sdsafsd",
"timeStamp" -> "sdsafsd",
"engTemp" -> "sdsafsd",
"tyrePressure" -> "sdsafsd"
).asInstanceOf[DBObject]
sensordatacollection.insert(eventObj) <- compiler error "No implicit view available from com.mongodb.casbah.commons.MongoDBObject.type => com.mongodb.casbah.commons.TypeImports.DBObject."
}
}
}
Thanks in advance.