Unable to connect to mongo using Spark Mongo Connector

1,063 views
Skip to first unread message

kant kodali

unread,
Sep 10, 2017, 4:40:23 PM9/10/17
to mongodb-user
Hi All,

I am using spark 2.2.0 and latest version of MongoDB. I am trying to do upserts from spark to mongo and I have the following line of code where the error happens. I need MongoConnector object for me to do upserts based on some criteria. Any help would be great

MongoConnector mongoConnector = MongoConnector.apply(sparkSession.sparkContext());

I am using the following jar

compile group: 'org.mongodb.spark', name: 'mongo-spark-connector_2.11', version: 2.2.0

I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/ConnectionString

at com.mongodb.spark.config.MongoCompanionConfig$$anonfun$4.apply(MongoCompanionConfig.scala:278)

at com.mongodb.spark.config.MongoCompanionConfig$$anonfun$4.apply(MongoCompanionConfig.scala:278)

at scala.util.Try$.apply(Try.scala:192)

at com.mongodb.spark.config.MongoCompanionConfig$class.connectionString(MongoCompanionConfig.scala:278)

at com.mongodb.spark.config.ReadConfig$.connectionString(ReadConfig.scala:39)

at com.mongodb.spark.config.ReadConfig$.apply(ReadConfig.scala:51)

at com.mongodb.spark.config.ReadConfig$.apply(ReadConfig.scala:39)

at com.mongodb.spark.config.MongoCompanionConfig$class.apply(MongoCompanionConfig.scala:124)

at com.mongodb.spark.config.ReadConfig$.apply(ReadConfig.scala:39)

at com.mongodb.spark.config.MongoCompanionConfig$class.apply(MongoCompanionConfig.scala:113)

at com.mongodb.spark.config.ReadConfig$.apply(ReadConfig.scala:39)


Thanks!

Wan Bachtiar

unread,
Oct 6, 2017, 8:23:05 PM10/6/17
to mongodb-user

Hi Kant,

It’s been a while since you posted this question, have you found a solution to your question ?

Based on the error messages your Spark job doesn’t seem to pick up the MongoDB Spark connector in the path.
Could you please provide:

  • The method on how you’re launching the Spark job ?
  • How are you defining MongoDB Spark connector ? 

You may also find MongoDB Spark Connector Scala Guide a useful resource.

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages