1

I am new to Apache Spark and I am using Scala and Mongodb to learn it. https://docs.mongodb.com/spark-connector/current/scala-api/ I am trying to read the RDD from my MongoDB database, my notebook script as below:

import com.mongodb.spark.config._
import com.mongodb.spark._

val readConfig = ReadConfig(Map("uri" -> "mongodb+srv://root:[email protected]/test_database.test_collection?retryWrites=true&w=majority"))

val testRDD = MongoSpark.load(sc, readConfig)
print(testRDD.collect)

At the print(testRDD.collect) line, I got this error:

java.lang.NoSuchMethodError: com.mongodb.internal.connection.Cluster.selectServer(Lcom/mongodb/selector/ServerSelector;)Lcom/mongodb/internal/connection/Server;

And more than 10 lines "at..."

Used libraries:

org.mongodb.spark:mongo-spark-connector_2.12:3.0.1
org.mongodb.scala:mongo-scala-driver_2.12:4.2.3

Is this the problem from Mongodb internal libraries or how could I fix it?

Many thanks

5
  • how did you package the jar? assembly build? Commented Aug 22, 2021 at 11:33
  • Ah, I am using Databricks to code. The libraries that I installed are from Maven. Commented Aug 22, 2021 at 12:07
  • I am using Databricks and Notebook to code. I don't use any Jars. I already tested with Python Script for the same feature and it also returns the same error Commented Aug 22, 2021 at 12:10
  • what Databricks runtime is used? Commented Aug 22, 2021 at 12:35
  • I tried both 7.3 LTS (includes Apache Spark 3.0.1, Scala 2.12) and 8.3 (includes Apache Spark 3.1.1, Scala 2.12) Both of them return the same error Commented Aug 22, 2021 at 14:06

2 Answers 2

1

I suspect that there is a conflict between mongo-spark-connector and mongo-scala-driver. The former is using Mongo driver 4.0.5, but the later is based on the version 4.2.3. I would recommend to try only with mongo-spark-connector

Sign up to request clarification or add additional context in comments.

Comments

0

I was also facing the same problem, solved it using mongo-spark-connector-2.12:3.0.1 jar and with that also added jar of Scalaj HTTP » 2.4.2. It's working fine now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.