Error No implicit view available from com.mongodb.casbah.commons.MongoDBObject.type => com.mongodb.c

43 views
Skip to first unread message

Veeresh Y

unread,
May 11, 2016, 12:32:12 AM5/11/16
to mongodb-casbah-users
Hi 
 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.


No implicit view available from com.mongodb.casbah.commons.MongoDBObject.type => com.mongodb.casbah.commons.TypeImports.DBObject.

Code 
myvents.foreachRDD { rdd =>
      rdd.foreachPartition { iterator =>
        val uri = MongoClientURI("mongodb://10.1.0.7:27017/")
        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."
        }
      }
    }

Is this a compatibility issue? 
Thanks in advance.
Veeresh


Reply all
Reply to author
Forward
0 new messages